{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","params":[],"results":{"codes":[]}},"next":{"description":"","pages":[]},"title":"Group Operation","type":"basic","slug":"group-operation","excerpt":"","body":"`GroupOperation` can be used to execute multiple `NSOperation` instances on a private queue. This is a very powerful class and probably the second most commonly used after `BlockOperation`. Advanced techniques will be discussed in a later section, here we will cover the basics.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Direct usage\"\n}\n[/block]\nInitialize a `GroupOperation` with an array of `NSOperation` instances. Dependencies set on the operations will also be respected.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let group = GroupOperation(operations: opOne, opTwo, opThree)\\ngroup.addObserver(FinishedObserver { op in\\n    // the group has finished, meaning all operations have finsihed.\\n})\\nqueue.addOperation(group)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nOnce the group has started, but has not finished, it is possible to add more operations to the group.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"group.addOperation(opFour)\\ngroup.addOperations([opFive, opSix])\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Cancellation\",\n  \"body\": \"Cancelling the group will cancel all operations in the queue.\"\n}\n[/block]","updates":[],"order":4,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"56740128f79ca90d00ad2f65","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"},"__v":4,"createdAt":"2015-12-18T12:50:48.095Z","user":"5654ea8be0d82b0d00ab5747","category":{"sync":{"isSync":false,"url":""},"pages":["567400df22cd7e0d00fada7f","56740103f65d9c0d002e3d5e","5674010f47f7010d005bff1a","56740128f79ca90d00ad2f65","5674014947f7010d005bff1c","5674015622cd7e0d00fada81","5674016058c4890d00bb5558"],"title":"Available Operations","slug":"available-operations","order":2,"from_sync":false,"reference":false,"_id":"567400638565060d009a86fb","__v":7,"createdAt":"2015-12-18T12:47:31.547Z","project":"5672fc989996590d00c22c65","version":"5672fc989996590d00c22c68"},"project":"5672fc989996590d00c22c65","githubsync":""}
`GroupOperation` can be used to execute multiple `NSOperation` instances on a private queue. This is a very powerful class and probably the second most commonly used after `BlockOperation`. Advanced techniques will be discussed in a later section, here we will cover the basics. [block:api-header] { "type": "basic", "title": "Direct usage" } [/block] Initialize a `GroupOperation` with an array of `NSOperation` instances. Dependencies set on the operations will also be respected. [block:code] { "codes": [ { "code": "let group = GroupOperation(operations: opOne, opTwo, opThree)\ngroup.addObserver(FinishedObserver { op in\n // the group has finished, meaning all operations have finsihed.\n})\nqueue.addOperation(group)", "language": "swift" } ] } [/block] Once the group has started, but has not finished, it is possible to add more operations to the group. [block:code] { "codes": [ { "code": "group.addOperation(opFour)\ngroup.addOperations([opFive, opSix])", "language": "swift" } ] } [/block] [block:callout] { "type": "info", "title": "Cancellation", "body": "Cancelling the group will cancel all operations in the queue." } [/block]