-1

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!

  • 2
    Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – tbilopavlovic Jul 06 '16 at 06:43
  • how you set tabBarController propert – Rohit Pradhan Jul 06 '16 at 06:51

1 Answers1

0

This is where it fails: let trendtbvc = tabBarController as! TrendsTabBarViewController, check that you have set your tab bar controller correctly.

tbilopavlovic
  • 1,096
  • 7
  • 13