Search code examples
iosswiftuitabbarcontroller

How do I access the viewControllers on the UITabbarController in swift?


I'm trying to get the 2nd viewcontroller of the tabbarcontroller so i can popToRoot but Swift tells me that using an Int as a subscript is not valid and I have to use an AnyObject as an index

var controller = self.viewControllers[2] as! UIViewController

error is "Cannot subscript a value of type [AnyObject]? with an Int"


Solution

  • var controller = self.viewControllers![2] as! UIViewController