I am using NSInvocationOperation
with NSOperationQueue
developing in iOS5.
According to apple documentation on invocation objects:
The NSInvocationOperation class is a concrete subclass of NSOperation... This class implements a non-concurrent operation.
Ok, so my NSInvocationOperation
object executes synchronously? (correct me here) Apple's docs also says on operation queue objects:
In iOS, operation queues do not use Grand Central Dispatch to execute operations. They create separate threads for non-concurrent operations and launch concurrent operations from the current thread.
I am using the NSInvocationObject
, which is a non-concurrent object, and adding it to to the operation queue like so:
[operationQueue addOperation:operation];
so my question is: 1) Since the operation queue will be spawning a separate thread to execute the NSInvocationObject as it says in the docs, will it be run asynchronously instead of synchronously?
[UPDATE - in response to Dani's answer below. Taken from an Apple link.
NSOperation and NSOperationQueue
There are a number of different ways that you can use NSOperation, but the most common is to write a custom subclass and override one method: main. The main method gets called to perform the operation when the NSOperationQueue schedules it to run. NSOperation classes written in this way are known as non-concurrent operations, because the developer is not responsible for spawning threads—multi-threading is all handled by the super class. (Don’t be confused by the terminology: just because an operation is non-concurrent, does not mean it cannot be executed concurrently, it simply means that you don't have to handle the concurrency yourself.)
If you need more control over threading and the run-time environment of your operations, you can make use of concurrent operations. To do this, you subclass NSOperation and override the start method. In the start method, you can spawn threads and setup the environment before calling the main method. You are also required to maintain the state of the NSOperation by setting properties like isExecuting and isFinished. In short, concurrent operations give you a lot more control, but also demand more effort—for most tasks non-concurrent operations suffice.