Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Method' is ambiguous for type lookup in this context, Error in Alamofire

I am using Alamofire for network handling in swift and run into one weird error. It seems like we can't pass Method enum as parameter.
[Error is on Method parameter]

enter image description here

private func apiRequest(method: Method, url: String, apiData: [String : AnyObject], completion:(finished: Bool, response: AnyObject?) ->Void) {

    Alamofire.request(method, url, parameters: apiData).responseJSON{ response in
        if let JSON = response.result.value {
            completion(finished: true, response: JSON)
        } else {
            completion(finished: false, response:nil)
        }
    }
}
like image 645
Ravi Prakash Avatar asked Nov 05 '15 11:11

Ravi Prakash


3 Answers

You have to specify the module from which to lookup object type. Call Alamofire.Method

like image 143
harpreetSingh Avatar answered Dec 06 '22 03:12

harpreetSingh


There is probably a name collision. To solve it, you can use the qualified name of the enum (including the module name):

private func apiRequest(method: Alamofire.Method, ...
like image 20
Sulthan Avatar answered Dec 06 '22 05:12

Sulthan


I have also encountered this problem, because I have declared a number of the same name of the protocol:

protocol SomeProtocol {
   static func someTypeMethod()
}

protocol SomeProtocol {
   init(someParameter: Int)
}

protocol SomeProtocol {
   var mustBeSettable: Int { get set }
   var doesNotNeedToBeSettable: Int { get }
}
like image 26
ylgwhyh Avatar answered Dec 06 '22 04:12

ylgwhyh