Reputation: 42692
I am new in iOS Swift 2.
I have defined a simple function:
// ERROR: 'Method' is ambiguous for type lookup in this context
func sendRequest(method: Method, resource: String) -> NSDictionary {
Alamofire.request(method, "https://httpbin.org/get")
}
As you see, I defined the first parameter has type Method
, which is used by Alamofire. I looked into the Method
, it is a Enum
defined as below:
public enum Method: String {
case OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT
}
Why I can not use enum type as parameter type of my function?
(The reason why I want to do this is I don't want to pass String
type and check if String is e.g. 'get'
then use .GET
, so, I want to directly pass the Method
enum value to the function.)
==== update ====
Method
is from Alamofire library, I can't change anything. Looks like it is a name conflicts. But how to get rid of this problem?
Upvotes: 0
Views: 245
Reputation: 9825
There compiler sees more than one type named Method
(Alamofire.Method
and ObjectiveC.Method
) and doesn't know which one you want to use for your function.
You have to prefix the type name with the module name to tell it which one to use:
func sendRequest(method: Alamofire.Method, resource: String) -> NSDictionary {
Alamofire.request(method, "https://httpbin.org/get")
}
Upvotes: 1
Reputation: 299663
Method
is ambiguous with the runtime type of the same name. I recommend selecting a different type name that does not collide with existing types.
Upvotes: 0