Skip to content

Instantly share code, notes, and snippets.

@alfian0
Created May 4, 2018 01:19
Show Gist options
  • Select an option

  • Save alfian0/937eb41fdba0446d0831a2ece42d3889 to your computer and use it in GitHub Desktop.

Select an option

Save alfian0/937eb41fdba0446d0831a2ece42d3889 to your computer and use it in GitHub Desktop.
extension UIViewController {
func add(_ child: UIViewController) {
addChildViewController(child)
view.addSubview(child.view)
child.view.frame = view.bounds
child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
child.didMove(toParentViewController: self)
}
func remove(_ child: UIViewController) {
child.willMove(toParentViewController: nil)
child.view.removeFromSuperview()
child.removeFromParentViewController()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment