Tôi đang cố gắng triển khai AlamofireObjectMapper
(https://github.com/tristanhimmelman/AlamofireObjectMapper) với Alamofire 3 và phiên bản mới nhất của ObjectMapper (https://github.com/Hearst-DD/ObjectMapper).Không thể chuyển đổi giá trị của loại 'T?' để loại đối số dự kiến '_?' - Các loại chung và khối hoàn thành
Dường như AlamofireObjectMapper
, chưa được cập nhật để hoạt động với Alamofire 3, vì vậy tôi đang cố gắng tự làm.
Tôi đã đến đoạn mã này và bây giờ tôi bị kẹt.
Dường như Generic Type T không thể truy cập được bên trong khối hoàn thành của phản hồi. Là thay đổi Alamofire
3 hoặc thay đổi Swift 2.1?
Đây là lỗi:
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 '_?'
}
}
}
}
Ha ha. May mắn là tôi đã nhìn thấy câu trả lời của bạn từ rất sớm. Đây là loại lỗi có thể mất hàng giờ để gỡ lỗi nhờ có các thông báo lỗi hữu ích. Cảm ơn rất nhiều – villy393
"Sử dụng toán tử chưa được giải quyết '**'" :( –
wow cảm ơn, lỗi đã được tham số tiếp theo cho tôi quá (chạy Xcode 8.0) – aryaxt