Skip to content

Instantly share code, notes, and snippets.

@kharmabum
Created December 14, 2018 21:49
Show Gist options
  • Save kharmabum/bdbef142878df6e72d1d95257d40ec15 to your computer and use it in GitHub Desktop.
Save kharmabum/bdbef142878df6e72d1d95257d40ec15 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