PFFile for PFImageView

I'm having problems displaying the image that I take from Parse in my iOS app. I decided to use PFImageView. This is what I have so far:

I declared PFImageView pic:

@IBOutlet var pic: PFImageView!

inside the request:

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

This is really strange, because others work (name and description), and I'm sure that I have a field called "image" in my database (yes small i). I always get this error: fatal error: unexpectedly found nil while deploying an optional value.

Any info on this?

+4
source share
2 answers

Check for nil file

if object.objectForKey("image") != nil
{
var imagefile = object["image"] as PFFile
self.pic.file = imagefile
self.pic.loadInBackground()
}
-2
source

try it

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

    self.pic.file = imagefile
    self.pic.loadInBackground()
    }
-2
source

All Articles