{"__v":5,"_id":"5674019122cd7e0d00fada83","category":{"__v":3,"_id":"5674017bf79ca90d00ad2f67","pages":["56740186f79ca90d00ad2f68","5674019122cd7e0d00fada83","567401b522cd7e0d00fada86"],"project":"5672fc989996590d00c22c65","version":"5672fc989996590d00c22c68","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-18T12:52:11.346Z","from_sync":false,"order":3,"slug":"ios-only-operations","title":"iOS only Operations"},"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-18T12:52:33.072Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"`UIViewController` has functionality for presenting other view controllers. This notion is wrapped into `UIOperation`. It is mostly useful as a building block for other presentation operations such as [`AlertOperation`](doc:alert-operation), but can be used directly inside a view controller too.\n\nWrapping view controller presentation inside and `Operation` is useful for two reasons\n\n1. We can add mutual exclusivity, which prevents other view controller presentations from occurring. This may sounds trivial, but given the asynchronous nature of application, it is not that unlikely that this could happen.\n2. We can attach observers to clean up or tear down the current UI. This might mean removing selection highlighting or freeing up memory. \n\n`UIOperation` is generic over two types. The controller being presented, which must be a `UIViewController` and the controller doing the presenting, which must conform to the `PresentingViewController` protocol. Operations framework adds conformance to `UIViewController` for this protocol.\n\nThe `PresentingViewController` protocol and `ViewControllerDisplayStyle` enum expresses the various methods for presenting one controller from another. Essentially, `.Show`, `.ShowDetail` and `.Present`.\n\nFor example, let assume we must present a login controller from our root controller:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let ui = UIOperation(\\n    controller: loginController, \\n    displayControllerFrom: .Present(from)\\n)\\nqueue.addOperation(ui)\",\n      \"language\": \"swift\",\n      \"name\": \"present controller\"\n    }\n  ]\n}\n[/block]\nAlternatively, maybe we have a split view controller and need to set the detail controller:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let show = DisplayDetailsViewController(from: .ShowDetail(self))\\nqueue.addOperation(show)\",\n      \"language\": \"swift\",\n      \"name\": \"show details of controller\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"ui-operation","type":"basic","title":"UI Operation"}
`UIViewController` has functionality for presenting other view controllers. This notion is wrapped into `UIOperation`. It is mostly useful as a building block for other presentation operations such as [`AlertOperation`](doc:alert-operation), but can be used directly inside a view controller too. Wrapping view controller presentation inside and `Operation` is useful for two reasons 1. We can add mutual exclusivity, which prevents other view controller presentations from occurring. This may sounds trivial, but given the asynchronous nature of application, it is not that unlikely that this could happen. 2. We can attach observers to clean up or tear down the current UI. This might mean removing selection highlighting or freeing up memory. `UIOperation` is generic over two types. The controller being presented, which must be a `UIViewController` and the controller doing the presenting, which must conform to the `PresentingViewController` protocol. Operations framework adds conformance to `UIViewController` for this protocol. The `PresentingViewController` protocol and `ViewControllerDisplayStyle` enum expresses the various methods for presenting one controller from another. Essentially, `.Show`, `.ShowDetail` and `.Present`. For example, let assume we must present a login controller from our root controller: [block:code] { "codes": [ { "code": "let ui = UIOperation(\n controller: loginController, \n displayControllerFrom: .Present(from)\n)\nqueue.addOperation(ui)", "language": "swift", "name": "present controller" } ] } [/block] Alternatively, maybe we have a split view controller and need to set the detail controller: [block:code] { "codes": [ { "code": "let show = DisplayDetailsViewController(from: .ShowDetail(self))\nqueue.addOperation(show)", "language": "swift", "name": "show details of controller" } ] } [/block]