代码:
1 2 3 4 5 6 7 8 | if !stream.connectWithTimeout(XMPPStreamTimeoutNone, error: &error) { var alert = UIAlertController(title: "Alert" , message: "Cannot connect to : \(error!.localizedDescription)" , preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Click" , style: UIAlertActionStyle.Default, handler: nil)) self.window?.rootViewController?.presentViewController(alert, animated: true , completion: nil) return false } |
出错:
SwiftXMPP/AppDelegate.swift:105:42: Extra argument ‘error’ in call

点击跳转,是对的:

搜:
swift stream.connectWithTimeout Extra argument ‘error’ in call
参考:
代码改为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | do { let isConnectOk = try stream.connectWithTimeout(XMPPStreamTimeoutNone) if isConnectOk { var alert = UIAlertController(title: "Alert" , message: "Cannot connect to : \(error!.localizedDescription)" , preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Click" , style: UIAlertActionStyle.Default, handler: nil)) self.window?.rootViewController?.presentViewController(alert, animated: true , completion: nil) return false } } catch { print(error) } |
[总结]
此处之所以提示:
Extra argument error in call
是因为:stream.connectWithTimeout
这类,之前把error当作参数传入的函数
现在新版swift的接口,都变成了:
参数中没了error
但是要强制用try catch去捕获error才可以
-》
所以改为do try catch的方式,就可以了
-》以后遇到类似的,之前旧版本api中带error参数的
记得,新版本api都改为,需要用do try catch的方式去捕获error,而调用时不带error参数了。
转载请注明:在路上 » [已解决]swift中SwiftXMPP代码出错:Extra argument error in call