{"__v":6,"_id":"567302a0dcbe1b0d007835e4","category":{"__v":3,"_id":"5673018a06b19d0d0010691b","pages":["567302825316790d001f8d6a","5673029345185e0d008bd1c2","5676d59a12ea5a2300726aba"],"project":"5672fc989996590d00c22c65","version":"5672fc989996590d00c22c68","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-17T18:40:10.078Z","from_sync":false,"order":4,"slug":"intermediate","title":"Advanced"},"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:44:48.470Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"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]","excerpt":"Responding to cancellation","slug":"cancellation","type":"basic","title":"Cancellation"}

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]