最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中SwiftXMPP代码出错:Extra argument error in call

Swift crifan 2969浏览 0评论
代码:
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
SwiftXMPP Extra argument error in call
点击跳转,是对的:
command click to jump to definition ok
搜:
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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.260 seconds, using 22.14MB memory