0

I cannot find the solution for the issue. I have the following code

let imgData = self.getImgData(id: (entry["id"] as? Int)!)
let imgToShow = UIImage(data: imgData as Data)

where imgToShow is this what I expected. I mean, when debugging it's giving me the preview of this what I want. So I am sure that it's correct and not nil.

public func getImgData(id: Int) -> NSData{
    let url = *
    let imgUrl = URL(string: url)!
    let imgData = NSData(contentsOf: imgUrl)!

    return imgData

}

I would like to assign this imgToShow to cell.img.image = imgToShow but it's giving me an error:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

Can you please give me some advice where should I look the solution? Thank you in advance

Salman Ghumsani
  • 3,491
  • 1
  • 17
  • 32
Micgal
  • 123
  • 1
  • 1
  • 11
  • post the code of `self.getImgData(id: (entry["id"] as? Int)!)` – Salman Ghumsani Sep 25 '17 at 10:00
  • Thanks, updated. But I can guess that the function works fine as I can see the preview of the image when debugging. – Micgal Sep 25 '17 at 10:03
  • If your claim that " `imgToShow` is not nil " is correct , then I think problem is in this part : `cell.img` , so please check that your cell is made properly and also check `img` property is correctly made – 3stud1ant3 Sep 25 '17 at 10:21
  • So, I have tried to use @SalmanGhumsani solution, calling `getImage(url) { (data) in cell.img.image = data }` The image has been downloaded, I can see it while debugging, but in line where assigning it to UIImageView getting the same. So could be the problem with `img`, which just looks like this: `class AuthorTableViewCell: UITableViewCell { @IBOutlet weak var img: UIImageView! override func awakeFromNib() { super.awakeFromNib() self.imgId.isHidden = true } } }` But where should I looking for – Micgal Sep 25 '17 at 10:52
  • It's working great! Thanks. So the problem was with UIImageView item, as there was very simple, stupid mistake. During refactoring I have changed the name of Outlet, but the old one name has been referenced. Just reconnected Outlet and this is what I want. I have wasted 2 days on it.. It was so simple. Anyway, thank you again for the lesson, that always should check references. – Micgal Sep 25 '17 at 11:03

1 Answers1

0

Try to reconnect the outlet!

Also, for getting download the image smoothly try it Downloading UIImage via AlamofireImage?

Salman Ghumsani
  • 3,491
  • 1
  • 17
  • 32