title: Why does UILabel.text result in “fatal error: unexpectedly found nil while unwrapping an Optional value”?
body: <p>I've read several answers to this question and have tried all recommendations with no success.  I'm fairly new to swift and am building an app with Swift, PHP and MySQL. I'm receiving the error after the user has logged in to the app and the system should be displaying the username via a label using <code>UILabel.text</code>.  The error is occurring on setting a value to the <code>UILabel.text</code> variable.  My code is included below.  I've tried to hardcode values on other pages and am getting this error throughout my project.</p>
  
  <pre><code>import UIKit
  
  class HomeViewController: UITabBarController {
  
      @IBOutlet var usernameLbl: UILabel!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // set global variables
          let username = (user!["username"] as AnyObject).uppercased
  
          // label values
          print(usernameLbl ?? username!)
          usernameLbl.text = username
      }
  }
  </code></pre>
  
  <p>I'm accessing the HomeViewController programmatically.  The app uses a tab bar and the first page of it is Home.  The code is from a course I'm taking on Udemy.  Here is how I'm accessing Home:</p>
  
  <pre><code>// func to pass to home page or to tabBar
  func login() {
  
      // refer to our Main.storyboard
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
  
      // store our tabBar Object from Main.storyboard in tabBar var
      let tabBar = storyboard.instantiateViewController(withIdentifier: "tabBar")
  
      // present tabBar that is storing in tabBar var
      window?.rootViewController = tabBar
  
  }
  </code></pre>