Main Thread Checker
kniort opened this issue · 2 comments
Hello guys,
After migrating to ios11 and Xcode 9, I have a warning for each toast :
Main Thread Checker: UI API called on a background thread: -[UIView init]
PID: 57662, TID: 5080800, Thread name: (none), Queue name: NSOperationQueue 0x600000425b20 (QOS: UNSPECIFIED), QoS: 0
The warning disappear if I add DispatchQueue.main.async(execute: { () -> Void in when I call the toast but I need to add this code in all toast call.
Do you have an idea to make the init view with thread main in the Toast Library Code ?
Thank you !
I have the same problem of it.
I add a class function in class Toast.
class func show(text: String?) {
DispatchQueue.main.async {
Toast(text: text).show()
}
}
And I use the method as following.
Toast.show(text: "One apple a day, keep doctor away")
I believe we could just document that Toast(text: text)
must be called on main thread, like for any UIKit class. Trying to do an asynchronous initialization to avoid that restriction would be kind of superfluous efforts.