Skip to content

Instantly share code, notes, and snippets.

@soffes
Created June 8, 2016 22:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/5e38295f8b21b856b798beb58660cc82 to your computer and use it in GitHub Desktop.
Save soffes/5e38295f8b21b856b798beb58660cc82 to your computer and use it in GitHub Desktop.
Easily access master and detail view controllers on UISplitViewController
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
}
}
@malhal
Copy link

malhal commented Jan 2, 2024

UISplitViewController has a private var detailViewController that this will interfere with!

@soffes
Copy link
Author

soffes commented Jan 2, 2024

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