Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Important is it to use `performSelectorOnMainThread:withObject:waitUntilDone:` From an NSOperation?
    text
    copied!<p>My iPad app syncs with an XML feed, running the sync in an NSOperation subclass executed from an NSOperationQueue. As it parses the feed, it calls back to the main thread via <code>performSelectorOnMainThread:withObject:waitUntilDone:</code> to update various parts of the UI, schedule downloads, etc. Some of this is pretty expensive; the UI can sometimes become unresponsive for a second or two as a sync is going on.</p> <p>To make the UI more responsive, I've removed the use of <code>performSelectorOnMainThread:withObject:waitUntilDone:</code> in favor of direct calls to perform all the sync-related tasks, including updating the UI. So now the sync takes place entirely on the background thread created by the NSOperationQueue. This seems to work pretty well, and the UI is much more responsive during a sync.</p> <p>However, I'm leery of releasing with it this way. I've seen some mentions in various places that one should only update the UI on the main thread (<a href="http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/" rel="nofollow">example with reference to AppKit</a>). But I've been unable to find anything specific on this topic in the documentation.</p> <p>So how important is it to update the UI on the main thread? Which parts of an app are thread-safe and which are not? Is there perhaps a reference explaining what's safe to execute in an NSOperation and what should be executed only on the main thread in iOS? Am I really doing something unsafe or crash-prone?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload