{"__v":3,"_id":"5673025a30d9800d003a2ea8","category":{"__v":3,"_id":"567301169d4c060d009da8b3","pages":["5673014406b19d0d00106919","567301539d4c060d009da8b4","56730163fc60740d00be8ab7"],"project":"5672fc989996590d00c22c65","version":"5672fc989996590d00c22c68","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-17T18:38:14.940Z","from_sync":false,"order":0,"slug":"getting-started","title":"Getting Started"},"project":"5672fc989996590d00c22c65","user":"5654ea8be0d82b0d00ab5747","version":{"__v":7,"_id":"5672fc989996590d00c22c68","project":"5672fc989996590d00c22c65","createdAt":"2015-12-17T18:19:04.699Z","releaseDate":"2015-12-17T18:19:04.699Z","categories":["5672fc999996590d00c22c69","567301169d4c060d009da8b3","56730183547bee0d00997d1a","5673018a06b19d0d0010691b","567301b53054630d00fe9288","567400638565060d009a86fb","5674017bf79ca90d00ad2f67"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.5.0","version":"2.5.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-17T18:43:38.449Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"`NSOperation` supports the concept of operations which depend on other operations finishing. An  operation is not limited to one dependency.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let greet = Greeter(name: \\\"Daniel\\\")\\nlet welcome = ShowWelcome()\\ngreet.addDependency(welcome)\\nqueue.addOperations(greet, welcome)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Set dependencies before adding operations to queues\",\n  \"body\": \"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.\"\n}\n[/block]\n`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`.","excerpt":"","slug":"dependencies","type":"basic","title":"Dependencies"}
`NSOperation` supports the concept of operations which depend on other operations finishing. An operation is not limited to one dependency. [block:code] { "codes": [ { "code": "let greet = Greeter(name: \"Daniel\")\nlet welcome = ShowWelcome()\ngreet.addDependency(welcome)\nqueue.addOperations(greet, welcome)", "language": "swift" } ] } [/block] [block:callout] { "type": "success", "title": "Set dependencies before adding operations to queues", "body": "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." } [/block] `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`.