Skip to content

Instantly share code, notes, and snippets.

@chriswill0w
Created June 8, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswill0w/f027d8c7307053a1fd45fb03477fbb06 to your computer and use it in GitHub Desktop.
Save chriswill0w/f027d8c7307053a1fd45fb03477fbb06 to your computer and use it in GitHub Desktop.
extension UIViewController {
func add(_ child: UIViewController) {
addChildViewController(child)
view.addSubview(child.view)
child.didMove(toParentViewController: self)
}
func remove() {
guard parent != nil else {
return
}
willMove(toParentViewController: nil)
removeFromParentViewController()
view.removeFromSuperview()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment