Last active
June 20, 2017 10:34
-
-
Save cemaleker/ff56eb226e315ea10fc6582e3fc36676 to your computer and use it in GitHub Desktop.
Container view controller helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIViewController { | |
func attachChildViewController(_ viewController: UIViewController) { | |
attachChildViewController(viewController, to: self.view) | |
} | |
func attachChildViewController(_ viewController: UIViewController, to view: UIView) { | |
self.addChildViewController(viewController) | |
view.addSubview(viewController.view) | |
viewController.didMove(toParentViewController: self) | |
} | |
func detachChildViewController(viewController: UIViewController) { | |
guard viewController.parent == self else { | |
return | |
} | |
viewController.willMove(toParentViewController: nil) | |
viewController.removeFromParentViewController() | |
viewController.view.removeFromSuperview() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment