Youtube App Lesson 6- Problem with not seeing anything in the cells

Hi code crew!

I am AJR and while doing Chris’ 6th lesson of the Youtube App Series, I encountered a problem. There is nothing displayed in each cell of the Table View. My code has been uploaded here: https://github.com/AJR-Coder/youtube-CodeWithCris-OneDayBuild Could you kindly help me check why is this so? Did I forget to type anything out? Thanks!

There was an error in your Video struct in the init() block where you perform all the decoding to get your Video properties.

Go back through the video and compare against your code.

Hi Chris Parker, I tried to change the code and I did notice a difference for the parsing of the title, however, it still did not solve the problem that there was no images/text in the prototype cell. I tried copying and pasting Chris’ Code but it didn’t work. Could it be anywhere else that has a problem?

Screenshot 2020-10-09 at 9.20.26 AM|546x500

When I get home tonight I will grab the code I changed to get it to work and post the entire project as a zip file (minus the Constants.swift file … I used mine) to Dropbox and paste a link here.

1 Like

Hi @AJR

Here is the link to the edited project.

I’ve gone through the code where I made changes and added comments to the end of the lines. I hope I got them all.

In Model for the GetVideos() function you had the following if statement:

if error != nil || data != nil {
    return
}

whereas the test should have been:

if error != nil || data == nil {
    return
}

The logic there is that if there is an error (ie, error is not nil) OR there is no data (ie, data is equal to nil) then return. What your code was doing was invoking return when the data is not nil.

There were a couple of changes inside the Video struct. These are related to the code in the init(from decoder: Decoder) throws {

My thinking in advising you to go back over the video was so that you could hopefully discover where the errors were and probably gain some good learning experience at the same time rather than me providing you with the corrected code.

Can I offer some advice related to your code:

When you name functions and variables, make sure that they are in camel case. For example in your Model where you have the function GetVideos() it should be getVideos(). In the struct Video, the variable var VideoId = "" should be var videoId = ""
Essentially the first letter of the first word should be lowercase. All the first letters in the following words in the name should be uppercase. eg: tableView, thumbnailImage, titleLabel, dateLabel, setCell()

This approach differs to class names, struct names, protocol names (for example), where they all have the first letter of the first word in uppercase as well. This will be very important if you ever take on an iOS Development job.

1 Like