Skip to content

Instantly share code, notes, and snippets.

@jeandavid
Created December 20, 2021 10:39
Show Gist options
  • Save jeandavid/13d49d997570b9009fd152d2f0be0cc6 to your computer and use it in GitHub Desktop.
Save jeandavid/13d49d997570b9009fd152d2f0be0cc6 to your computer and use it in GitHub Desktop.
Add and remove child view controllers
import UIKit
extension UIViewController {
func add(_ child: UIViewController) {
addChild(child)
view.addSubview(child.view)
child.didMove(toParent: self)
}
func remove() {
willMove(toParent: nil)
view.removeFromSuperview()
removeFromParent()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment