Created
October 6, 2015 22:04
-
-
Save jaminguy/8b76393fed4c66988cc2 to your computer and use it in GitHub Desktop.
This file contains 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
import Foundation | |
import UIKit | |
protocol ViewControllerContaining { | |
var containerView: UIView! { get set } | |
func addViewController(childViewController: UIViewController) | |
func removeViewController(childViewController: UIViewController) | |
func addChildViewController(childController: UIViewController) | |
} | |
extension ViewControllerContaining { | |
func addViewController(childViewController: UIViewController) { | |
self.addChildViewController(childViewController) | |
childViewController.view.frame = containerView.bounds | |
containerView.addSubview(childViewController.view) | |
childViewController.didMoveToParentViewController(self as? UIViewController) | |
} | |
func removeViewController(childViewController: UIViewController) { | |
childViewController.willMoveToParentViewController(nil) | |
if childViewController.isViewLoaded() { | |
childViewController.view.removeFromSuperview() | |
} | |
childViewController.removeFromParentViewController() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment