Skip to content

Instantly share code, notes, and snippets.

@Kharauzov
Created February 27, 2020 16:00
Show Gist options
  • Save Kharauzov/e0185f21a05387faab72ac4373bcacec to your computer and use it in GitHub Desktop.
Save Kharauzov/e0185f21a05387faab72ac4373bcacec to your computer and use it in GitHub Desktop.
Basic methods to work with child view controllers
func add(_ child: UIViewController, shouldAddView: Bool = false) {
addChild(child)
if shouldAddView {
view.addSubview(child.view)
}
child.didMove(toParent: self)
}
func remove(shouldRemoveView: Bool = false) {
guard parent != nil else {
return
}
willMove(toParent: nil)
if shouldRemoveView {
view.removeFromSuperview()
}
removeFromParent()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment