Kobazzo
Kobazzo

Reputation: 574

"unexpectedly found nil while unwrapping an Optional value" when retriveing PFFile from Parse.com

i've a problem when i retrieve a PFFile stored in Parse.com

let user = PFUser.currentUser()
let userImageFile = user["profileImage"] as PFFile
            userImageFile.getDataInBackgroundWithBlock {
                (imageData: NSData!, error: NSError!) -> Void in
                if error == nil {
                    if imageData != nil{
                        let image = UIImage(data:imageData)
                        self.profileImage.image = image
                    }
                }
            }

The error start at line two. Column "profileImage" exists, but it can be empty.

Someone can help me? Thank you.

Upvotes: 2

Views: 924

Answers (1)

Tom Erik Støwer
Tom Erik Støwer

Reputation: 1409

Try:

if let userImageFile = user["profileImage"] as? PFFile {

}

Upvotes: 2

Related Questions