Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://eschatologist.net/blog/?p=232" rel="nofollow noreferrer">Common</a> <a href="https://stackoverflow.com/questions/10373331/nsoperation-vs-grand-central-dispatch">advice</a> is to use the highest level of abstraction available to you to perform a task. As such <code>NSThread</code> should be relatively low down in the list of things you can do to execute work in the background.</p> <p>The order you investigate APIs should be like this:</p> <ol> <li><a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004591" rel="nofollow noreferrer">NSOperation</a> / <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html" rel="nofollow noreferrer">NSOperationQueue</a></li> <li><a href="http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html" rel="nofollow noreferrer">Grand Central Dispatch</a> (libdispatch)</li> <li>NSThread</li> <li>POSIX threads</li> </ol> <p>With the first two you write your code as a "unit of work" and then put this work on a queue to be executed at some point. The system takes care of creating and destroying threads for you and the APIs are easy to work with. Here's an example using <code>NSOperationQueue</code>.</p> <pre><code>NSBlockOperation * blockOperation = [NSBlockOperation blockOperationWithBlock:^{ //Do work //update your UI on the main thread. [self performSelectorOnMainThread:@selector(workDone:) withObject:workResults waitUntilDone:NO]; }]; [self.operationQueue addOperation:blockOperation]; </code></pre> <p>easy as that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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