Reputation: 55
I have a TabBarController with four different UIViews connected to it. The TabBarController is managed from the Controller.swift file, which looks like that
import UIKit
import Firebase
class Controller: UITabBarController {
var firebaseUser = String()
override func viewDidLoad() {
super.viewDidLoad()
//let allVC = self.tabBarController?.viewControllers
//let SearchVC = allVC![1] as! SearchVC
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
However, the lines that are commented out lead to the error "...found nil while unwrapping optional.." (already getting allVC leads to the error)
How can I fix that error?
Upvotes: 2
Views: 2251
Reputation: 20804
Use let allVC = self.viewControllers
instead as your class is a UITabBarViewController
subclass
Upvotes: 9