Operations are an object-oriented way to encapsulate work that you want to perform asynchronously. Operations are designed to be used either in conjunction with an operation queue or by themselves
Operations State
An operation has a state machine that represents its lifecycle. There are several possible states that occur at various parts of this lifecycle:
- When it’s been
instantiated, it will transition to theisReady state. - When we invoked the
startmethod, it will transition to theisExecutingstate. - When the task
finished, it moves toisFinished - When task is in progress and you call
cancel, then it will transition to theisCancelled state before moving onto theisFinished state
1. BlockOperation (Concrete Class) 2. NSInvocationOperation (Concrete Class) 3. Custom Operations ***BlockOperation (Concrete Class) A class you use as-is to execute one or more block objects concurrently. Because it can execute more than one block, a block operation object operates using a group semantic; only when all of the associated blocks have finished executing is the operation itself considered finished.. In block operation you can take advantage of operation dependencies, KVO, notifications and cancelling.Operation objects execute in a synchronous manner by default — that is, they perform their task in the thread that calls their start method.
0 Comments
Leave a Comment