Youtube App won't load image or title thumbnails

Hi, during the lesson 6 of the Youtube App around the 22-minute mark Chris demos the thumbnail images, title and date. For some reason, I run the app and it comes up as blank images and no labels.

https://ibb.co/2nLLfwP

I’ve checked proxyman and the app is accessing my Youtube API so I’m not sure what could be causing this problem.

Any help would be much appreciated!

Hi @BonesOnFire

Have you set breakpoints in your code so that you can look at the values in console as the function setCell progresses?

Hey, @Chris_Parker thanks for the suggestion!

I set breakpoints in the setCell function, however, the debugger never hits them. I pause the debugger and get this:

1 libsystem_kernel.dylib`mach_msg_trap:
2 0x7fff523b6220 <+0>: movq %rcx, %r10
3 0x7fff523b6223 <+3>: movl $0x100001f, %eax ; imm = 0x100001F
4 0x7fff523b6228 <+8>: syscall
5 -> 0x7fff523b622a <+10>: retq Thread 1: signal SIGSTOP
6 0x7fff523b622b <+11>: nop

There is a green SIGSTOP error on line 5 and when I step into it I get this:

-> 0x7fff523b67fc <+204>: cmpl $0x10004005, %eax ; imm = 0x10004005

I’m not sure what this error means if it means anything at all. This happens after the line:

func setCell(_ v:Video) {

    //Ensure that we have a video
    guard self.video != nil else {
                   return
           }

If I set a breakpoint before that the debugger works. I’m sure that I have videos because before I made the VideoTableViewCell.swift file the simulator was accessing the titles to the videos just fine. I’m not sure what could be the issue. Here are images in case they are helpful.


In your setCell function when the breakpoint stops at the line self.video = v

In your Console where you see the (lldb) in green, type:

po v.thumbnail

and press return to see if there is a value returned which should be a url to the video thumbnail. That will at least prove that there is a video url being returned.

Hi @Chris_Parker

I do end up getting a url, here is the result:

Imgur

Hi @BonesOnFire

Great, that’s what I expected you to see.

What does the rest of your setCell code look like? Have you added all the code that downloads the image data in the URLSession?

Also, what does your cellForRowAt code look like in your ViewController.swift file?

By the way, you can embed images in your post by either dragging them I’m and dropping them at the point you want or you can tap on the image icon and select the image from Finder.

@Chris_Parker

Here is my cellForRow at code:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return videos.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let cell = tableView.dequeueReusableCell(withIdentifier: Constants.VIDEOCELL_ID, for: indexPath) as!
    VideoTableViewCell
    
    //Configure the cell with the data
    let video = self.videos[indexPath.row]
    
    cell.setCell(video) 
    
    //Return the cell
    return cell 
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
}

I have added all the code that downloads the image data of the URLSession as well as kicked off the data task.

here is the rest of my setCell code:

Hmmmm, is the Custom Class for the VideoCell in ViewController in your storyboard set to VideoTableViewCell?

Screen Shot 2020-07-06 at 9.29.00 amScreen Shot 2020-07-06 at 9.30.39 am

@Chris_Parker

Yes, see here:

Man, this has got me puzzled.

I’m away from my laptop at the moment but if you want to share your project on DropBox by posting a link to it in a reply, I can have a look at it tonight my time which it UTC + 8 or +12 New York time

Remove the API-KEY before you zip it

@Chris_Parker

Thanks man, I really appreciate that. Sorry for the late response I was away from home. No rush, just whenever you have a minute. I’ve removed the API key so you may need to add your own.

@BonesOnFire

Found the problem.

In setCell() in VideoTableViewCell you had:

func setCell(_ v:Video) {
        
        
    //Ensure that we have a video
    guard self.video != nil else {
        return
    }
        
    self.video = v
        
    //Set the title label
    self.titleLabel.text = video?.title
    .
    .
    .
    .

and what was happening is that the test on self.video was always going to be nil because video was not being set. The following line of code self.video = v needed to be before it. So your code should have been like this:

func setCell(_ v:Video) {
        
    self.video = v
                
    //Ensure that we have a video
    guard self.video != nil else {
        return
    }
        
    //Set the title label
    self.titleLabel.text = video?.title
    .
    .
    .
    .

So with that correction it works spot on.

:+1:

1 Like

Here’s a screenshot using the CodeWithChris playlist ID.

1 Like

@Chris_Parker

Thanks man you’re a real lifesaver! That was a hard one to notice.

1 Like