gpt4 book ai didi

swift - 无法推断通用参数(swift 3)

转载 作者:可可西里 更新时间:2023-10-31 23:14:28 26 4
gpt4 key购买 nike

我在我的项目中使用 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)
}
}

最佳答案

尝试将参数类型更改为 [String: Any]

关于swift - 无法推断通用参数(swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39724831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com