Created
February 27, 2020 16:00
-
-
Save Kharauzov/e0185f21a05387faab72ac4373bcacec to your computer and use it in GitHub Desktop.
Basic methods to work with child view controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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