"在打开一个Optional值时意外发现nil"当从Parse.com重审PFFile时

时间:2014-09-20 11:44:50

标签: swift parse-platform ios8 xcode6

当我检索存储在Parse.com中的PFFile时,我遇到了问题

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
                    }
                }
            }

错误从第二行开始。 专栏" profileImage"存在,但它可以是空的。

有人可以帮帮我吗? 谢谢。

1 个答案:

答案 0 :(得分:2)

尝试:

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

}
相关问题