無法調用非函數類型'NSHTTPURLResponse?'的值無法調用非函數類型'NSHTTPURLResponse?'的值Alamofire ObjectMapper
有人可以幫我嗎?
下面是代碼
public func responseObject<T: Mappable>(queue: dispatch_queue_t?, keyPath: String?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, ErrorType?) -> Void) -> Self {
return response(queue: queue, responseSerializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { request, response, result in
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
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 ?? result.data, result.error)
}
}
}
}
我的壞,我沒有注意到Alamofire 2.0的返回類型,
這是固定的,更新的代碼是在這裏
public func responseObject<T: Mappable>(queue: dispatch_queue_t?, keyPath: String?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, ErrorType?) -> Void) -> Self {
let serializer = Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)
return response(queue: queue, responseSerializer: serializer) { (Response) -> Void in
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let parsedObject = Mapper<T>().map(keyPath != nil ? Response.result.value?[keyPath!] : Response.result.value)
dispatch_async(queue ?? dispatch_get_main_queue()) {
completionHandler(self.request!, self.response, parsedObject, Response.result.value ?? Response.result.value, Response.result.error)
}
}
}
}
我試過使用Alamofire 2.0響應串行器,這也給出了相同的錯誤 – Abh
請寫下你的代碼,不要發佈一個屏幕截圖。 – SJuan76
我已經添加了代碼。任何想法? – Abh