NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

How to type cast a masterViewController when using splitViewControllers

Forums > Swift

I've got the following code:

guard let splitViewController = self.window?.rootViewController
          as? UISplitViewController else {
          fatalError("Missing SplitViewController")

        guard let masterNavController = splitViewController.viewControllers.first
          as? UINavigationController,
          let masterViewController = masterNavController.topViewController
          as?  MasterViewController else {
          fatalError("Missing MasterViewController")

        splitViewController.preferredDisplayMode = .primaryHidden
        splitViewController.delegate = masterViewController

I've read and understood the relevant reference, yet I don't know what I should conditionally type cast masterViewController constant as. I'm getting 'MasterViewController is an undeclared type' compiler error.


Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.