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



我在我的项目中使用AFNetworking和Mantle库。我决定迁移swift 3。我得到了这个错误-> "通用参数'ResponseType'无法推断"对getSources函数

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]

相关内容

  • 没有找到相关文章

最新更新