Created
June 8, 2016 22:23
-
-
Save soffes/5e38295f8b21b856b798beb58660cc82 to your computer and use it in GitHub Desktop.
Easily access master and detail view controllers on UISplitViewController
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
| import UIKit | |
| extension UISplitViewController { | |
| convenience init(masterViewController: UIViewController, detailViewController: UIViewController) { | |
| self.init() | |
| viewControllers = [masterViewController, detailViewController] | |
| } | |
| var masterViewController: UIViewController? { | |
| return viewControllers.first | |
| } | |
| var detailViewController: UIViewController? { | |
| guard viewControllers.count == 2 else { return nil } | |
| return viewControllers.last | |
| } | |
| } |
Author
Hah I wonder when that was added. Maybe just rename them to master and detail :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UISplitViewControllerhas a privatevar detailViewControllerthat this will interfere with!