Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Created January 29, 2018 09:04
Show Gist options
  • Save andr3a88/9fdf35a307b59ee13293a13141592f32 to your computer and use it in GitHub Desktop.
Save andr3a88/9fdf35a307b59ee13293a13141592f32 to your computer and use it in GitHub Desktop.
Extension: Add and remove child view controller
/// Add a child view controller
///
/// - Parameter child: The child view controller
func add(_ child: UIViewController) {
addChildViewController(child)
view.addSubview(child.view)
child.didMove(toParentViewController: self)
}
/// Remove the view controller from the parent
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