【发布时间】:2016-09-27 12:34:59
【问题描述】:
我在我的项目中使用 AFNetworking 和 Mantle 库。我决定迁移 swift 3。我得到了这个错误 -> getSources 函数上的“无法推断通用参数'ResponseType'”
ApiBaseHelper.swift
class func GET<ResponseType>(url: String, parameters: AnyObject!, path: String!, callback: @escaping (_ operation: AFHTTPRequestOperation?, _ result: [ResponseType]?, _ error: Error?) -> ()) -> AFHTTPRequestOperation! where ResponseType: MTLJSONSerializing, ResponseType: MTLModel{
return NetworkManager.sharedInstance!.get(url, parameters: parameters,
success: {(operation: AFHTTPRequestOperation?, result: Any?) -> Void in
self.parseResponse(response: result as AnyObject!, operation: operation, path: path, callback: callback)
},
failure: { (operation: AFHTTPRequestOperation?, error: Error?) -> Void in
print("error get request => \(error)")
callback(operation, nil, error as Error?)
}
)
}
ApiHelper.swift
class func getSources(_ callback: @escaping (_ operation: AFHTTPRequestOperation?, _ contents: [Source]?, _ error: Error?) -> ()) {
var params = [String: AnyObject]()
params["apiKey"] = API_KEY as AnyObject?
let url = String(format: SOURCE_PATH)
//generic parameter 'ResponseType' could not be inferred
GET(url: url, parameters: params as AnyObject!, path: "sources") { (operation: AFHTTPRequestOperation!, result: [Source]?, error: Error!) -> () in
callback(operation, result, error)
}
}
【问题讨论】:
-
我有类似架构和 Alamofire 的同样问题
标签: swift generics afnetworking swift3 mantle