0

I'm not managing to assign a value. recognizes me "category" as a constant. have I tried with as? but, of course, he tells me "Use of undeclared type 'category"

class FeedCell: UITableViewCell {

@IBOutlet weak var category: UILabel!
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var labelTitle: UILabel!
@IBOutlet weak var labelSubtitle: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
}

// assembled the cell
func updateCell(withFeedItem feedItem: RSSFeedItem) {
    var imageLink = ""
    var category = ""

    for media in (feedItem.media!.mediaThumbnails)! {
        imageLink = media.attributes?.url ?? "No image"
    }
    for categories in feedItem.categories! {
        category = categories.value ?? "None"

        guard let mediaThumbnails = feedItem.media?.mediaThumbnails,
            let categories = feedItem.categories else { return }

        for media in mediaThumbnails {
            imageLink = media.attributes?.url ?? "No image"
        }
        for category in categories {
            category = category.value ?? "None"
        }
    }

    self.myImageView.sd_setImage(with: URL(string: imageLink), completed: nil)
    self.labelTitle.text = feedItem.title
    self.labelSubtitle.text = feedItem.description
    self.category.text = category
}

}

Riccardo Caroli
  • 341
  • 1
  • 3
  • 12

2 Answers2

1

It looks like you have an Exception Breakpoint enabled. This will pause execution as soon as an error is thrown. Just like if you had a breakpoint set at this point of your code.
You can either (1)disable it or (2)press "Continue" to proceed with the crash and get the debugger output.

enter image description here

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
  • Fatal error: Unexpectedly found nil while unwrapping an Optional value 2019-05-17 10:49:01.798202+0200 News EI[2831:815672] Fatal error: Unexpectedly found nil while unwrapping an Optional value (I insert !) – Riccardo Caroli May 17 '19 at 08:49
1

Force unwrapping should be avoided. In your loops you are forcefully unwrapping feedItem.categories and feedItem.media?.mediaThumbnails. If those are optionals, then there should be some reason for that. You should first use guard or if let statements, so you will be sure those are not nil and be able to work with them however you want. You can read here more about how to do safe unwrapping.