简体   繁体   English

迁移 Swift 和更新 Alamofire 后,我的路由器不工作

[英]My Router doesn't work after migration of Swift and update of Alamofire

I'm doing the migration of my app on Swift 2.0.我正在 Swift 2.0 上迁移我的应用程序。 I took the opportunity to also migrate Alamofire from 1.3 to 2.0.我也借此机会将 Alamofire 从 1.3 迁移到 2.0。

But now my app is not working anymore, and i got many errors on the file where i use Alamofire.但是现在我的应用程序不再工作了,而且我在使用 Alamofire 的文件中遇到了很多错误。

First on my enum Router declaration i got an error who say首先在我的枚举路由器声明中,我得到了一个错误,他说

private enum Router: URLRequestConvertible {

EDIT: Here is the beginning of the methods that implement编辑:这是实现方法的开始

URLRequestConvertible URLRequestConvertible

    // MARK: URLRequestConvertible

    var URLRequest: NSURLRequest {
        let URL = Router.baseURL.URLByAppendingPathComponent(self.path)
        let URLRequest = NSMutableURLRequest(URL: URL)
        URLRequest.HTTPMethod = self.method.rawValue

        switch self {
        case .Login(let email, let password):
            return self.encoding.encode(URLRequest, parameters: [
                "email": email,
                "password": password]).0

        case .Logout:
            return self.encoding.encode(URLRequest, parameters: nil).0
}

Type 'Router' does not conform to protocol 'URLRequestConvertible'类型“路由器”不符合协议“URLRequestConvertible”

Second in all my request when i'm gonna check the .responseJSON { (_, _, json, error) in i got an error who say当我要检查.responseJSON { (_, _, json, error) in i got an error who say

Tuple types '(NSURLRequest?, NSHTTPURLResponse?, Result)' (aka '(Optional, Optional, Result)') and '(_, _, _, _)' have a different number of elements (3 vs. 4)元组类型 '(NSURLRequest?, NSHTTPURLResponse?, Result)' (aka '(Optional, Optional, Result)') 和 '(_, _, _, _)' 具有不同数量的元素(3 对 4)

EDIT: Ok no more error field but how do you do your error handling so ?编辑:好的,不再有error field但是您如何进行错误处理呢?

EDIT2: Ok got it now you need do use a switch for the Result. EDIT2:好的,现在你需要为结果使用一个开关。 Thx谢谢

Error that i didn't had before我以前没有的错误

Thanks for your help !谢谢你的帮助 !

For the second error refer to the Alamofire page here https://github.com/Alamofire/Alamofire对于第二个错误,请参阅此处的Alamofire页面https://github.com/Alamofire/Alamofire

As you can see they changed the .responseJSON which now returns just 3 parameters.如您所见,他们更改了.responseJSON ,现在只返回 3 个参数。 In version 1.3 there were 4 parameters instead.在 1.3 版中有 4 个参数。 Basically you simply have to delete the error field in this way基本上你只需要以这种方式删除error字段

.responseJSON { (_, _, json) in

我认为你需要返回 'NSMutableURLRequest' 而不是 'NSURLRequest' 如果你还没有改变它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM