swiftswift2watchos-2watchos

How to get live instance of interface controller in watchOS?


In my ExtensionDelegate, I'd like to get an instance of one of my interface controllers. I'm using a page-based navigation.

For example, I can do this in iOS like this:

if let controller = self.tabBarController?.viewControllers?[1] as? TimesController {
 controller.myVariable = nil
}

How can I do this in watchOS?


Solution

  • You can't. There's no concept of a page view controller on watchOS which would hold an array of interface controllers.

    Since you can't pass another context in preparation for a page segue, you would need to update that specific interface controller's property within its willActivate() method:

    override func willActivate() {
        super.willActivate()
        myVariable = ...
    }