I am presenting the UIAlertController
on the main thread as :
class HelperMethodClass: NSObject { class func showAlertMessage(message:String, viewController: UIViewController) { let alertMessage = UIAlertController(title: "", message: message, preferredStyle: .alert) let cancelAction = UIAlertAction(title: "Ok", style: .cancel) alertMessage.addAction(cancelAction) DispatchQueue.main.async { viewController.present(alertMessage, animated: true, completion: nil) } } }
And I am calling the method from any UIViewController
as:
HelperMethodClass.showAlertMessage(message: "Any Message", viewController: self)
I am getting the output properly.
But in console I am getting below message:
[Assert] Cannot be called with asCopy = NO on non-main thread.
Is there something I have done wrong here or I can ignore this message ?
Edit
Thanks to @NicolasMiari :
Adding below code is not showing any message:
DispatchQueue.main.async { HelperMethodClass.showAlertMessage(message: "Any Message", viewController: self) }
What can be the reason that previously it was showing the message in console?
You should call all code from showAlertMessage
on main queue:
class func showAlertMessage(message:String, viewController: UIViewController) { DispatchQueue.main.async { let alertMessage = UIAlertController(title: "", message: message, preferredStyle: .alert) let cancelAction = UIAlertAction(title: "Ok", style: .cancel) alertMessage.addAction(cancelAction) viewController.present(alertMessage, animated: true, completion: nil) } }
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