title: Crash while unwrapping an Optional Value
body: <p>I am getting an error. It is returning nil on a DispatchQueue call.</p>
  
  <pre><code>DispatchQueue.main.async {
       self.headerImageView.image = image // &lt;- CRASH
  }
  </code></pre>
  
  <p>Turns out that this is where I am getting a crash.</p>
  
  <p><code>headerImageView</code> is just a variable which is not connected to the storyboard via <code>IBOutlet</code>. Here is the entire code:</p>
  
  <pre><code>import UIKit
  import WebKit
  
  let offset_HeaderStop:CGFloat = 40.0
  let offset_B_LabelHeader:CGFloat = 95.0
  let distance_W_LabelHeader:CGFloat = 35.0
  
  class MovieDetailsViewController: UIViewController, UIScrollViewDelegate {
  
      var movie: Movie?
      var urlBuilder = MovieUrlBuilder()
      var config = TMDBConfiguration()
  
      @IBOutlet weak var scrollView: UIScrollView!
      @IBOutlet weak var headerView: UIView!
      @IBOutlet weak var headerLabel: UILabel!
      @IBOutlet weak var titleLabel: UILabel!
      @IBOutlet weak var genreLabel: UILabel!
      @IBOutlet weak var ratingLabel: UILabel!
      @IBOutlet weak var releaseLabel: UILabel!
      @IBOutlet weak var descriptionText: UITextView!
      @IBOutlet weak var trailerContainerView: UIView!
      @IBOutlet weak var trailerLabel: UILabel!
      @IBOutlet weak var videoContainer: WKWebView!
  
      var headerImageView: UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          scrollView.delegate = self
      }
  
      override func viewDidAppear(_ animated: Bool) {
  
          headerImageView = UIImageView(frame: headerView.bounds)
          headerImageView.image = UIImage(named: "Poster")
          headerImageView.contentMode = .scaleAspectFill
          headerView.insertSubview(headerImageView, belowSubview: headerLabel)
          headerView.clipsToBounds = true
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          fetchPopularMovies()
      }
  
      func scrollViewDidScroll(_ scrollView: UIScrollView) {
  
          let offset = scrollView.contentOffset.y
          var headerTransform = CATransform3DIdentity
  
          if offset &lt; 0 {
              let headerScaleFactor: CGFloat = -(offset) / headerView.bounds.height
              let headerSizeVariation = ((headerView.bounds.height * (1.0 + headerScaleFactor)) - headerView.bounds.height)/2.0
              headerTransform = CATransform3DTranslate(headerTransform, 0, headerSizeVariation, 0)
              headerTransform = CATransform3DScale(headerTransform, 1.0 + headerScaleFactor, 1.0 + headerScaleFactor, 0)
  
              headerView.layer.transform = headerTransform
          } else { 
              headerTransform = CATransform3DTranslate(headerTransform, 0, max(-offset_HeaderStop, -offset), 0)
              let labelTransform = CATransform3DMakeTranslation(0, max(-distance_W_LabelHeader, offset_B_LabelHeader - offset), 0)
              headerLabel.layer.transform = labelTransform
          }
  
          headerView.layer.transform = headerTransform
      }
  
      override var preferredStatusBarStyle: UIStatusBarStyle{
          return UIStatusBarStyle.lightContent
      }
  
      private func fetchPopularMovies() {
          if let poster = movie?.backdropPath {
              let baseURL = URL(string: config.baseImageURL)!
              let url = baseURL.appendingPathComponent("w500").appendingPathComponent(poster)
              let request = URLRequest(url: url)
  
              let task = urlBuilder.session.dataTask(with: request) {(data, response, error) in
                  do {
                      if let image = UIImage(data: data!) {
                          DispatchQueue.main.async {
                              self.headerImageView.image = image // &lt;- CRASH
                          }
                      }
                  }
              }
              task.resume()
          }
      }
  
  }
  </code></pre>
  
  <p>Thank you for the support!</p>