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

[已解决]swift Type () does not conform to protocol BooleanType

Swift crifan 2441浏览 0评论

代码:

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

出错:

SwiftXMPP/AppDelegate.swift:117:20: Type ‘()’ does not conform to protocol ‘BooleanType’

Type does not conform to protocol BooleanType

 

参考:

“Type ‘()’ does not conform to protocol ‘BooleanType'”:iOSProgramming
最后改为:
            do{
                try stream.connectWithTimeout(XMPPStreamTimeoutNone)
            }catch{
                let alert = UIAlertController(title: "Alert", message: "Cannot connect to : \(error)", preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
                self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)

                return false
            }
才通过编译了。
感觉像是:
ObjC的代码:
- (BOOL)connectWithTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr;
原先用法是:
            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
            }
现在改为:
            do{
                try stream.connectWithTimeout(XMPPStreamTimeoutNone)
            }catch{
                let alert = UIAlertController(title: "Alert", message: "Cannot connect to : \(error)", preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
                self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)

                return false
            }
才可以。

转载请注明:在路上 » [已解决]swift Type () does not conform to protocol BooleanType

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.176 seconds, using 22.08MB memory