I'm getting this error:
Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
I know it means that I forced unwrapped an optional. But the problem is that it happens in this line of code:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! TableViewCell //This is the problem
let object = self.fetchedResultsController.object(at: indexPath)
cell.nameLabel.text = object.title
if let imgURL = object.imageURL {
let realURL = NSURL(string: imgURL)
let data = NSData(contentsOf: (realURL as URL?)!)
cell.imgView.image = UIImage(data: data! as Data)
}
return cell
}
So my guess was that I made a mistake when I assigned the class to the Cell or the identifier, but I have double checked and it's the correct. I'm not sure what else can be the problem. I have to say, I made the code in another project template (it's a blog reader feature) to test it first and then I copied the code (It was working), so I'm not sure if it can be the origin of the problem.
Any ideas of what else can I do?
*This is the code inside the TableViewCell:
import UIKit
import CoreData
class TableViewCell: UITableViewCell {
@IBOutlet weak var imgView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
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
}
}