Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

swift3 - Alamofire Type 'ParameterEncoding' has no member 'URL' 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?

// 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
            }
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like a lot has changed in Swift 3. Try to change your code by taking reference as below code.

func asURLRequest() throws -> URLRequest {
        let url = URL(string: Router.baseURLString)!
        var urlRequest = URLRequest(url: url.appendingPathComponent(path))
        urlRequest.httpMethod = method.rawValue

        if let token = Router.OAuthToken {
            urlRequest.setValue("Bearer (token)", forHTTPHeaderField: "Authorization")
        }

        switch self {
        case .createUser(let parameters):
            return try Alamofire.JSONEncoding.default.encode(urlRequest, with: parameters)
        case .updateUser(_, let parameters):
            return try Alamofire.URLEncoding.default.encode(urlRequest, with: parameters)
        default:
            return urlRequest
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...