0
    let grouparray = userGroupArray[indexPath.row]
    let url = NSURL(string: grouparray.valueForKeyPath("image_thumbnail") as! String)!
    let data = NSData(contentsOfURL:url)
    cell.RightImage?.image = UIImage(data: data!)

This code i have used to get the image but i'm getting "unexpectedly found nil while unwrapping an Optional value" error.

Raj
  • 25
  • 10
  • i guess you're getting nil because there IS NO image at the moment. because for example the download needs too long – David Seek Sep 27 '16 at 11:58
  • check that image exist on that url or not ? – Umair Afzal Sep 27 '16 at 11:58
  • check your "image_thumbnail" have proper link and also your data get some content from that url. Or instead of this use image lazy loading or SDWebImages for image from url. – Max Sep 27 '16 at 11:59
  • Read the linked article. You should not force unwrap these optionals. Instead, use safe unwrapping with optional binding and handle possible errors like the URL being wrong or the file not being there. – Eric Aya Sep 27 '16 at 12:00
  • image is there , i'm getting the nil in NSData(contentsOfURL:url) – Raj Sep 27 '16 at 12:03
  • Probably your URL doesn't point to the image correctly like you think. Debug the URL value. – Eric Aya Sep 27 '16 at 12:03
  • im getting the correct URL – Raj Sep 27 '16 at 12:05
  • @Eric Aya where is the link – Raj Sep 27 '16 at 12:32
  • If your URL is correct and the image is there, then you have no issue! But you do have an issue. So, no, your image or your link are not correct. Debug. Print the values. *Show us what you get.* – Eric Aya Sep 27 '16 at 12:56

0 Answers0