我在主线上呈现UIAlertController
条:
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)
}
}
}
我从任何UIViewController
个方法中调用该方法:
HelperMethodClass.showAlertMessage(message: "Any Message", viewController: self)
我得到了正确的输出.
但在控制台中,我得到了以下信息:
在非主线程上,不能使用asCopy=NO调用[Assert].
是我做错了什么,还是我可以忽略这个信息?
Edit
感谢@NicolasMiari:
添加以下代码不会显示任何消息:
DispatchQueue.main.async {
HelperMethodClass.showAlertMessage(message: "Any Message", viewController: self)
}
之前它在控制台中显示消息的原因是什么?