代码:
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’

参考:
最后改为:
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