Alamofire 类型“ParameterEncoding"没有成员“URL"Swift 3 [英] Alamofire Type 'ParameterEncoding' has no member 'URL' Swift 3
本文介绍了Alamofire 类型“ParameterEncoding"没有成员“URL"Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的代码从 swift 2 版本迁移到 swift 3 版本.我无法迁移以下代码部分,也没有找到任何解决方案.我该怎么做?
I am trying to migrate my codes from swift 2 version to swift 3 version. I could not migrate following code part and I did not find any solution for it. How can I do it?
//标记:URLRequestConvertible
// MARK: URLRequestConvertible
public var URLRequest: NSMutableURLRequest {
let urlComponent = NSURLComponents(string: Router.baseURL)!
urlComponent.path = Router.basePath.stringByAppendingString(path)
let mutableURLRequest = NSMutableURLRequest(URL: urlComponent.URL!)
mutableURLRequest.HTTPMethod = method.rawValue
var parameters: [String: AnyObject] = Dictionary()
parameters["key"] = Router.key
parameters["hl"] = "en"
switch self {
case .getMostPopularVideos(let pageToken):
parameters["part"] = "snippet,contentDetails,statistics"
parameters["chart"] = "mostPopular"
parameters["videoCategoryId"] = TubeTrends.Settings.topTrendsCat
if let pageToken = pageToken {
parameters["pageToken"] = pageToken
}
return Alamofire.ParameterEncoding.URL.encode(mutableURLRequest, parameters: parameters).0 //This part Giving Error like Alamofire Type 'ParameterEncoding' has no member 'URL'
// default:
// return mutableURLRequest
}
}
}
推荐答案
我将这个计算属性的名称更改为,例如,request
,以避免与新的类型名称发生冲突,<代码>URLRequest.巧合的是,这个计算属性应该使用一种 URLRequest
:
I'd change the name of this computed property to, say, request
, to avoid clashing with the new type name, URLRequest
. Coincidentally, this computed property should use a type of URLRequest
:
public var request: URLRequest {
let url = URL(string: Router.baseURL)!
.appendingPathComponent(Router.basePath)
.appendingPathComponent(path)
var request = URLRequest(url: url)
request.httpMethod = method.rawValue
var parameters = [String: Any]()
parameters["key"] = Router.key
parameters["hl"] = "en"
switch self {
case .getMostPopularVideos(let pageToken):
parameters["part"] = "snippet,contentDetails,statistics"
parameters["chart"] = "mostPopular"
parameters["videoCategoryId"] = TubeTrends.Settings.topTrendsCat
if let pageToken = pageToken {
parameters["pageToken"] = pageToken
}
return try! Alamofire.URLEncoding.default.encode(request, with: parameters)
}
}
这篇关于Alamofire 类型“ParameterEncoding"没有成员“URL"Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文