'Conflict between Antitypical Result and Alamofire Result
I have the following Swift function in a protocol that represents a POST HTTP request:
func post<T: Mappable>(url: NSURL, parameters: [String: AnyObject]?, completion: ((Result<T, APIClientError>) -> ())?)
In this case, I'm doing import Result to get Result from Antitypical, because I don't want this protocol to depend on Alamofire.
In an implementation of this protocol, I want to use Alamofire to do the actual HTTP request:
func post<T: Mappable>(url: NSURL, parameters: [String: AnyObject]?, completion: (Result<T, APIClientError> -> ())? = nil) {
Alamofire.request(.POST, url.URLString, parameters: parameters, encoding: .JSON)
.validate()
The problem is that there is a conflict between Antitypical's Result and Alamofire's Result:
AlamofireHTTPClient.swift:21:87: 'Result' is ambiguous for type lookup in this context
How can I specify that I want to use Result from Antitypical? Or if you know a better way to solve the problem?
Solution 1:[1]
You can specify the exact type you are referring to by moduleName.Type; In your case that would be Result.Result or Alamofire.Result .
Solution 2:[2]
Swift 5
In Swift 5, you can specify the Swift result type as:
Swift.Result<T, APIClientError>
Alamofire can be done as:
Alamofire.Result<Data>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marius |
| Solution 2 | D. Greg |
