9
votes

When you use threads, do you have any preferences? In general rule, to use any of these techniques :

  • create a new thread manually and use the run loop
  • use NSOperationQueue
  • or use Grand Central Dispatch and the C version with dispatch_queue?

Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function?

2

2 Answers

10
votes

I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy" espoused by Larry Wall but sometimes I wonder.)

So my order of preference would be:

  1. Asynchronous method calls
  2. NSOperationQueue
  3. Grand Central Dispatch
  4. Thread

There an increase in complexity and flexibility with each step down. If you need the extra flexibility then the complexity is probably worth it.

3
votes

I can remember that in a WWDC 2010 session it was said that GCD is the way to go unless you are working with APIs that currently do not work well with it.

As a general rule, I always use asynchronous method calls for networking and avoid using pthreads or NSThreads directly unless it is absolutely necessary.