Introduced in Mac OS X v10.5, operation objects and operation queue objects simplify the job of executing multiple, finite tasks in a concurrent manner. Operation objects provide a way for you to encapsulate tasks into distinct objects. Each subclass of NSOperation that you create represents a unique type of task to be performed by your application. When you want to perform one of these tasks, simply create the appropriate operation object and either run it directly or add it to an operation queue.
The encapsulation provided by operation objects makes them a good way to manage your application’s independent tasks. Encasing the data and behavior for a given task inside a single object provides a clean demarcation between that task and the rest of your application. Having individual tasks inside objects also makes it easier to reuse those tasks in other code.
One of the other great benefits of operation objects, though, is the ability to add them to an operation queue. An operation queue manages the execution of operation objects within separate threads of your application. You do not have to write any thread creation or management code to make this happen either. The operation queue takes care of all the thread management work behind the scenes so that you can focus on what you want to run, and not how you want to run it. Operation queues can also manage interoperation dependencies to make sure your tasks execute in the correct order.
The following sections provide background on operation objects and show you how to define custom operation objects and run them with and without an operation queue. Even if you do not plan to run tasks in separate threads, you should consider using operation objects to manage tasks. The encapsulation they provide makes for better code reuse and management over time.
About Operation Objects and Operation Queues
Configuration Options for Operation Objects
Defining Operation Objects
Running Operations
Last updated: 2008-02-08