Skip to content

Instantly share code, notes, and snippets.

@kharmabum
Created December 14, 2018 21:49
Show Gist options
  • Select an option

  • Save kharmabum/bdbef142878df6e72d1d95257d40ec15 to your computer and use it in GitHub Desktop.

Select an option

Save kharmabum/bdbef142878df6e72d1d95257d40ec15 to your computer and use it in GitHub Desktop.

Revisions

  1. Juan-Carlos Foust created this gist Dec 14, 2018.
    17 changes: 17 additions & 0 deletions UIViewController-ChildControllers.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    extension UIViewController {
    func add(_ child: UIViewController) {
    addChildViewController(child)
    view.addSubview(child.view)
    child.didMove(toParentViewController: self)
    }

    func remove() {
    guard parent != nil else {
    return
    }

    willMove(toParentViewController: nil)
    removeFromParentViewController()
    view.removeFromSuperview()
    }
    }