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)
}
}
DispatchQueue doesn't behave like serial queue
DispatchQueue(label: "be.io")
will create a new instance every time you call it
To get as you expect make it an instance var like
let mySerialQueue = DispatchQueue(label: "be.io")
Why calling a dialog with a struct drops this exception?
The error message give a big clue:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Modifications to the
layout engine must not be performed from a background thread after it
has been accessed from the main thread.' terminating with uncaught
exception of type NSException
The URLRequest run asynchronously on a background thread, including its completion handlers. You (generally) can't do UI work outside of the main thread. To display the results you need to push the operation back onto the main thread:
DispatchQueue.main.async {
// do UI work
}
DispatchQueue main isn't called
I assume this code is in the main thread.
If so, you have sync'd to a background thread and from there tried to sync back to DispatchQueue.main
. But that queue is waiting for the background one to return before it can do anything.
Related Topics
Error Using Associated Types and Generics
Why Is There a Memory Leak at String Creation in Swift
How to Make a Swift Framework Submodule Really Private
Update Core Data Object Order - Not Working
Format String with Trailing Zeros Removed for X Decimal Places in Swift
In Swiftui How to Set the Environment Variable of Editmode in an Xcodepreview
Cancelling an Alamofire Request Wrapped in Nsoperation Causes Multiple Kvo
Easiest Way to Find Square Root in Swift
How to Set an Ordered Relationship with Nspersistentcloudkitcontainer
How to Get the Download Progress with the New Try Await Urlsession.Shared.Download(...)
Iaps Actually Validating the Receipt (Swift)
Swiftui @Environmentobject Error: May Be Missing as an Ancestor of This View
Handling Network Error in Combination with Binding to Tableview (Moya, Rxswift, Rxcocoa)