I had some code that created and added UIView subviews via a queue created by [[NSOperationQueue alloc] init], and it led to strangely laggy behavior. Subviews were only added after abnormally long delays.
But then I switched to using [NSOperationQueue mainQueue] for these parts, and responsiveness turned normal.
I would just like an explanation for the laggy behavior I saw using the first approach.
From Apple doc
In addition, UI classes are not thread-safe according to the thread programming guide.
So, avoid to update the UI from a thread different from the main thread.
If you run an
NSOperation(within a queue) you could update your UI (for example after having download some data required for your app lifecycle) performing a method in the main thread like the following:Or you could send a notification to the component that need to update the UI like:
The component that needs to update the UI will register for that notification like