I have a perfectly working code in Objective-C that is called to change the selected tab programmatically based on certain criteria.
-(void)loadNewView
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController setSelectedIndex:2];
[tabBarController.delegate tabBarController:tabBarController didSelectViewController:[tabBarController.viewControllers objectAtIndex:2]];
}
I am trying to get the equivalent of the same in Swift and below is the code I have tried
func loadNewView() {
var tabbarController: UITabBarController = self.window?.rootViewController as UITabBarController
tabbarController.selectedIndex = 2
var svc = tabbarController.viewControllers[2] as UINavigationController
tabbarController.delegate?.tabBarController(tabbarController, didSelectViewController:svc)
}
However I am getting the "[AnyObject]? does not have a member named subscript". I know something is wrong with the above Swift code but can anybody help me in understanding the error?