Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created October 8, 2017 10:53
Show Gist options
  • Save dmytro-anokhin/d4d18b49708cac121361116000db2317 to your computer and use it in GitHub Desktop.
Save dmytro-anokhin/d4d18b49708cac121361116000db2317 to your computer and use it in GitHub Desktop.
var leftViewController: UIViewController? {
willSet {
guard let child = leftViewController else { return }
child.willMove(toParentViewController: nil)
child.view.removeFromSuperview()
child.removeFromParentViewController()
}
didSet {
guard let child = leftViewController else { return }
loadViewIfNeeded() // Make sure the view is loaded
addChildViewController(child)
child.view.frame = leftContainerView.bounds
leftContainerView.contentView = child.view // Layout managed by container view
child.didMove(toParentViewController: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment