I have a "main" tab bar view controller and I am trying to pass variables to one of the tabs to be used in its own view controller, so in the view did load of the "main" controller I have the following:
override func viewDidLoad() {
super.viewDidLoad()
let trendtbvc = tabBarController as! TrendsTabBarViewController
trendtbvc.testText = "Test"
}
and in the TrendsTabBarViewController I am just trying to set a test variable to "Test".
class TrendsTabBarViewController: UITabBarController {
var testText: String?
override func viewDidLoad() {
super.viewDidLoad()
print(testText)
}
}
But when i run it, I get the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
I feel like this is going to be a simple answer and I'm missing something obvious, but I can't work it out. Any help would be really appreciated!