Alamofire Type 'ParameterEncoding' has no member 'URL' Swift 3

后端 未结 2 1818
误落风尘
误落风尘 2020-12-19 13:40

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?

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 13:57

    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)
        }
    }
    

提交回复
热议问题