title: Getting " unexpectedly found nil" error when setting "self imageView! image" in Swift
body: <p>I am getting the above error in this collection view-detail view code.</p>
  
  <p><code>Detail VC</code>:</p>
  
  <pre><code>class DetailViewController: UIViewController {
  
      @IBOutlet weak var imageView: UIImageView?
  
      var photo: NSDictionary?
  
      var image1:UIImage = UIImage()
  
      override func viewDidLoad() {
  
      super.viewDidLoad()
  
      // Do any additional setup after loading the view.
      //downloadFromUrl(url)
      if let photo = photo {
          let url1 = (photo["images"]!["thumbnail"]!!["url"])! as! String
          let url:NSURL = NSURL(string: url1 as String)!
          //print(url)
          downloadFromUrl(url)
      }
  
  
  }
  
  
        func downloadFromUrl(url: NSURL) {
      //self.imageView.hnk_setImageFromURL(url)
      let config:NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
      let session:NSURLSession = NSURLSession(configuration: config)
      let request:NSURLRequest = NSURLRequest(URL: url)
      let task = session.downloadTaskWithRequest(request) { (location, response, error) -&gt; Void in
  
          let data:NSData = NSData(contentsOfURL: location!)!
          let image:UIImage = UIImage(data: data)!
  
          dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
  
                  self.image1 = image
                  print(self.image1)
  
                  self.imageView.image = self.image1
  
          })
      }
  
  
      task.resume()
  
  
  }        
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  }
  </code></pre>
  
  <p>And here is some methods in <code>collection VC</code>:</p>
  
  <pre><code>override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! PhotosViewCell
  
      cell.backgroundColor = UIColor.brownColor()
  
      cell.photo = self.photos[indexPath.row] as? NSDictionary
  
      //self.p = self.photos[indexPath.row] as! NSDictionary
      //print("Link is \(cell.photo!["link"]!)")
  
      return cell
  }
  
  override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
  
      let p = self.photos[indexPath.row] as! NSDictionary
      let VC:DetailViewController = DetailViewController()
      VC.photo = p
  
      self.presentViewController(VC, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>I know I am probably getting this error because <strong><em>viewDidLoad()</em></strong> is not yet ready but what is the solution and I do need this dictionary inside <strong><em>viewDidLoad()</em></strong> because I need to call that <strong><em>downloadFromUrl()</em></strong> method.</p>
  
  <p>Oh, I am not using <strong><em>prepareforsegue()</em></strong> method. tried that too, maybe I was doing wrong.
  In the debug area, I am getting the following:</p>
  
  <pre><code> 2016-01-06 13:30:55.075 AuthCheck[3623:74910] Warning: Attempt to present    &lt;AuthCheck.DetailViewController: 0x7ff103dfb6c0&gt; on &lt;AuthCheck.PhotosViewController: 0x7ff103c2fd90&gt; whose view is not in the window  hierarchy!
    &lt;UIImage: 0x7ff103cd1820&gt;, {150, 150}
    fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>Which means correct image is being downloaded but it is not being able to set to imageView's image property. No idea why?
  Will someone tell me the solution please?</p>