I'm trying to implement AlamofireObjectMapper
(https://github.com/tristanhimmelman/AlamofireObjectMapper) with Alamofire 3 and latest version of ObjectMapper (https://github.com/Hearst-DD/ObjectMapper).
It seems that AlamofireObjectMapper
, hasn't been updated to work with Alamofire 3, so I'm trying to do it myself.
I've come to this piece of code and now i'm stuck.
It seems that the Generic Type T is not accesible inside the completion block of the response. Is a Alamofire
3 change or a Swift 2.1 change?
This is the error:
Cannot convert value of type 'T?' to expected argument type '_?'
public func responseObject<T: Mappable>(queue: dispatch_queue_t?, keyPath: String?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, ErrorType?) -> Void) -> Self {
return response(queue: queue) { (request, response, data, error) -> Void in
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let JSONResponseSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
let result = JSONResponseSerializer.serializeResponse(request, response, data, error)
let parsedObject = Mapper<T>().map(keyPath != nil ? result.value?[keyPath!] : result.value)
dispatch_async(queue ?? dispatch_get_main_queue()) {
completionHandler(self.request!, self.response, parsedObject, result.value ?? response.data, result.error) // Here it shows the error: Cannot convert value of type 'T?' to expected argument type '_?'
}
}
}
}
Just found the solution. It seemed to be a problem of the Xcode 7.1 beta compiler. It was giving the problem on the "parsedObject" parameter and there was a mistake on the next parameter.
completionHandler(self.request!, self.response, parsedObject, **result.value ?? data**, result.error)
So, if you happen to get the same error, review all the other parameters are ok.
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With