Swift 2.1 - 调用可以抛出,但是没有用'try'标记,错误没有被处理
Swift 2.1 - Call can throw, but it is not marked with 'try' and the error is not handled
我在使用以下代码时遇到错误,我该如何解决?
'调用可以抛出,但是没有标明'try'错误未处理'
let reachability = Reachability.reachabilityForInternetConnection() // - Error Here
reachability.whenReachable = { reachability in
if reachability.isReachableViaWiFi() {
let alertController = UIAlertController(title: "Alert", message: "Reachable via WiFi", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
else {
let alertController = UIAlertController(title: "Alert", message: "Reachable via Cellular", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
reachability.whenUnreachable = { reachability in
let alertController = UIAlertController(title: "Alert", message: "Not Reachable", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
reachability.startNotifier() // - Error Here
}
我在使用以下代码时遇到错误,我该如何解决?
'调用可以抛出,但是没有标明'try'错误未处理'
let reachability = Reachability.reachabilityForInternetConnection() // - Error Here
reachability.whenReachable = { reachability in
if reachability.isReachableViaWiFi() {
let alertController = UIAlertController(title: "Alert", message: "Reachable via WiFi", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
else {
let alertController = UIAlertController(title: "Alert", message: "Reachable via Cellular", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
reachability.whenUnreachable = { reachability in
let alertController = UIAlertController(title: "Alert", message: "Not Reachable", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
reachability.startNotifier() // - Error Here
}