我正在尝试将代码从Swift 2版本迁移到Swift 3版本。我无法迁移以下代码部分,也没有找到任何解决方案。我该怎么做?
//标记: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:
request
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) } }