Created
January 29, 2018 09:04
-
-
Save andr3a88/9fdf35a307b59ee13293a13141592f32 to your computer and use it in GitHub Desktop.
Extension: Add and remove child view controller
This file contains 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
/// 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