NSOperation supports the concept of operations which depend on other operations finishing. An operation is not limited to one dependency.

let greet = Greeter(name: "Daniel")
let welcome = ShowWelcome()
queue.addOperations(greet, welcome)


Set dependencies before adding operations to queues

A great aspect of this features is that the dependency can be setup between operations in different queues. However, we recommend that if possible all operations involved in a dependency graph are added to the same queue at the same time.

Operation has the concept of finishing (or cancelling) with errors, whereas NSOperation does not, they always just finish. If a dependency finishes with an error, and it is the dependency of another operation, that operation will still execute despite this failure. This is a pretty subtle behavior, and it may change in future versions. However, there are helper methods to catch cancellations, errors and ensure dependencies succeeded which we'll get into later. But consider that before your Operation subclass executes its work it is a best practice to validate assumptions using assert or precondition.

Did this page help you?