4

I'm having troubles displaying an image I'm taking from Parse in my iOS App. I decided to use the PFImageView. This is what I have so far:

I declared the PFImageView pic:

@IBOutlet var pic: PFImageView!

inside the query:

self.name.text = object["Name"] as String

var imagefile = object["image"] as PFFile
self.pic.file = imagefile
self.pic.loadInBackground()

self.desc.text = object["Description"] as String

It's really odd, because the others are working (name and description) and I am sure that I have a field named "image" in my database (yes small i). I always get this error: fatal error: unexpectedly found nil while unwrapping an Optional value.

Any insights into this?

Joshua
  • 325
  • 2
  • 12

2 Answers2

-2

Check if the file is nil

if object.objectForKey("image") != nil
{
var imagefile = object["image"] as PFFile
self.pic.file = imagefile
self.pic.loadInBackground()
}
Krtko
  • 1,055
  • 18
  • 24
-2

Try this

if let imagefile = object["image"] as PFFile {

    self.pic.file = imagefile
    self.pic.loadInBackground()
    }
jmcastel
  • 1,365
  • 7
  • 17
  • 34