Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// That’s marked @nonobjc so it won’t conflict with any of Apple’s own code, now or in the future.
@nonobjc extension UIViewController {
func add(_ child: UIViewController, frame: CGRect? = nil) {
addChildViewController(child)
if let frame = frame {
child.view.frame = frame
}
view.addSubview(child.view)
child.didMove(toParentViewController: self)
}
func remove() {
guard parent != nil else {
return
}
willMove(toParentViewController: nil)
view.removeFromSuperview()
removeFromParentViewController()
} }
//usage:
guard let vc = storyboard?.instantiateViewController(withIdentifier: "Second") else { return }
add(vc)
performSlowWork(with: data) {
vc.remove()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.