DispatchQueue : Cannot be called with asCopy = NO on non-main thread
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) }}