News app Lesson5 Optional is nil

Hi!
I checked again and again and tried a lot of ways… (and checked the solution)
I do not find the answer to my problem:

Maybe somebody can help me out?
(Working with XCode12)

Thanks, Nina

…apart from that I have an additional issue
(has been discussed in the topics here, but it couldn´t really solve my problem…)

Here it is:

020-12-10 10:58:37.435900+0100 News[29540:3094986] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed

Hi Nina,

Ignore the error/warning:

020-12-10 10:58:37.435900+0100 News[29540:3094986] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed

Hi Nina,

With regards to your

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Check that your articleImageView is correctly connected to your associated storyboard ViewContoller.

Looking at your code the fact that you got to that line of code before it crashed also tells me that you do not have an error from the dataTask and you have data. The if statement:
if error == nil && data != nil has tested as true which confirms that.

try running your app using a different simulator

Hi Chris,
thanks for your answer!! I checked everything again and watched the Video Lesson 4 and Lesson 5 for doublechecking…
Still no App running

I will send you the screenshot of @IBOutlet (should be ok, as far as I can see) and my code. If we do not find the point I will start from scratch again…
(As I also can´t scroll the articles up and down this might be the best idea :frowning: )

Hi Francis,
thanks! I tried with Iphone 12, but it didn´t change anything unfortunately…

this was for the libquic error btw, see if it is still there… it may be better to try running it on an older iphone maybe iphone x?

If you can’t scroll the tableView then that’s a bit odd.

Can you try using the keyboard command Shift + Option + Command + K

This is a build folder clean but is supposedly a deeper clean that might (or might not) make a difference.

I tried it. It didn´t change my result.
Thanks nevertheless!!

I send my code from ArticleCell.swift. If you are still thinking that it makes sense to check that, I would be happy. Apart from that I start a new NewsApp now and try my luck…

//
// ArticleCell.swift
// News
//
// Created by Nina Klee on 09.12.20.
//

import UIKit

class ArticleCell: UITableViewCell {

@IBOutlet weak var headlineLabel: UILabel!

@IBOutlet weak var articleImageView: UIImageView!


var articleToDisplay:Article?

func displayArticle(_ article:Article) {
    
    // Clean up the cell before displaying the next article
    articleImageView = nil
   headlineLabel.text = ""
    
    // Keep a reference to the article
    articleToDisplay = article
    
    // Set the headline
    headlineLabel.text = articleToDisplay!.title
    
    
    // Download and display the image
    
    
    // Check that the article actuallay has an image
    guard articleToDisplay!.urlToImage != nil else {
        return
    }
    
    
    // Create url string
    let urlString = articleToDisplay!.urlToImage
    
    // Create the url - - Ausrufezeichen von mir eingefuegt wg Fehlermeldung (without ! there is an error)
    let url = URL(string: urlString!)
    
    // Check that the url isn´t nil
    guard url != nil else {
        print("Couldn´t create url object")
        return
    }
    
    // Get a URLSession
    let session = URLSession.shared
    
    // Create a datatask
    let dataTask = session.dataTask(with: url!) { (data, response, error) in
        
        // Check that there were no errors
        if error == nil && data != nil {
            
            // Check it the url string that the data task went off to download matches the article this cell is set to display (this text is just in the solution, is not shown in the video as far as I know...:
        //  if self.articleToDisplay!.urlToImage == urlString {
                
                DispatchQueue.main.async {
                    // Display the image data in the image view
                    self.articleImageView.image = UIImage(data: data!)
                    
                        }

    }   // End if
     
} // End data task
    
    // Kick off the datatask
    dataTask.resume()

}



override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

Hi Francis,
I even tried with the 8. It is still the same… :woozy_face:

I built a new app. Now it works. Thanks for your support!!

1 Like