{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Cancellation","type":"basic","slug":"cancellation","excerpt":"Responding to cancellation","body":"`NSOperation` instances can be cancelled, responding to cancellation effecting will ensure that overall performance of the queue and application is optimal. There are a number of situations which require attention regarding cancellation\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Check whether the operation has been cancelled\"\n}\n[/block]\nBefore doing *work* inside the `Operation` subclass, it is a best practice to check whether the operation has already been cancelled. Let's revisit our first `Operation` subclass, and do it properly :)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import Operations\\n\\nclass MyFirstOperation: Operation {\\n    override func execute() {\\n        guard !cancelled else { return }\\n        print(\\\"Hello World\\\")\\n        finish()\\n    }\\n}\",\n      \"language\": \"swift\",\n      \"name\": \"check cancelled property before doing work\"\n    }\n  ]\n}\n[/block]","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"567302a0dcbe1b0d007835e4","project":"5672fc989996590d00c22c65","category":{"sync":{"isSync":false,"url":""},"pages":["567302825316790d001f8d6a","5673029345185e0d008bd1c2","5676d59a12ea5a2300726aba"],"title":"Advanced","slug":"intermediate","order":4,"from_sync":false,"reference":false,"_id":"5673018a06b19d0d0010691b","createdAt":"2015-12-17T18:40:10.078Z","project":"5672fc989996590d00c22c65","__v":3,"version":"5672fc989996590d00c22c68"},"githubsync":"","user":"5654ea8be0d82b0d00ab5747","__v":6,"createdAt":"2015-12-17T18:44:48.470Z","version":{"version":"2.5.0","version_clean":"2.5.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5672fc999996590d00c22c69","567301169d4c060d009da8b3","56730183547bee0d00997d1a","5673018a06b19d0d0010691b","567301b53054630d00fe9288","567400638565060d009a86fb","5674017bf79ca90d00ad2f67"],"_id":"5672fc989996590d00c22c68","__v":7,"createdAt":"2015-12-17T18:19:04.699Z","project":"5672fc989996590d00c22c65","releaseDate":"2015-12-17T18:19:04.699Z"}}

Cancellation

Responding to cancellation

`NSOperation` instances can be cancelled, responding to cancellation effecting will ensure that overall performance of the queue and application is optimal. There are a number of situations which require attention regarding cancellation [block:api-header] { "type": "basic", "title": "Check whether the operation has been cancelled" } [/block] Before doing *work* inside the `Operation` subclass, it is a best practice to check whether the operation has already been cancelled. Let's revisit our first `Operation` subclass, and do it properly :) [block:code] { "codes": [ { "code": "import Operations\n\nclass MyFirstOperation: Operation {\n override func execute() {\n guard !cancelled else { return }\n print(\"Hello World\")\n finish()\n }\n}", "language": "swift", "name": "check cancelled property before doing work" } ] } [/block]