I just updated my xcode8 to Swift 3 and I received this error:
Value of type 'DispatchQueue' has no member 'asynchronously'
on this line:
DispatchQueue.main.asynchronously(execute:
Here's the entire snippet:
DispatchQueue.main.asynchronously(execute: {
//Display alert message with confirmation
let myAlert = UIAlertController(title: "Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title:"OK", style:UIAlertActionStyle.Default){
action in self.dismissViewControllerAnimated(true, completion:nil);
}
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated:true, completion:nil);
});
}
}
catch let error as NSError {
print(error.localizedDescription)
}
}
task.resume()
}
}
Recently updating to Swift 3 has given me a lot of errors, they automatically fixed but this one will not fix on its own and I do not know what to do.
In the production release of Swift 3 and iOS 10, there is no asynchronously
method. It's just async
:
DispatchQueue.main.async {
//Display alert message with confirmation
let alert = UIAlertController(title: "Alert", message: messageToDisplay, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default) { action in
self.dismiss(animated: true)
}
alert.addAction(okAction)
self.present(alert, animated: true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With