When you use threads, do you have any preferences? In general rule, to use any of these techniques :
Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function?
NSOperationQueue works best when tasks are discrete, synchronous and live in the same thread (eg they are more or less atomic), the queue can be used as basic thread pool though in almost any situation.
Grand Central Dispatch is a low-level C API that interacts directly with Unix level of the system. NSOperation is an Objective-C API and that brings some overhead with it. Instances of NSOperation need to be allocated before they can be used and deallocated when they are no longer needed.
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:
NSOperationQueue
There an increase in complexity and flexibility with each step down. If you need the extra flexibility then the complexity is probably worth it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With