2014-09-20 61 views
2

retriveing PFFile当我一个问题,当我检索存储在Parse.com一个PFFile“意外发现零而展开的可选值”从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 
        } 
       } 
      } 

误差起始于线两条 。 列“profileImage”存在,但可以为空。

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

回答

2

尝试:

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

} 
+0

是的!谢谢。 解决方法: if let userImageFile = user [ParseUserClassTablesName.PROFILEIMAGE.description()] as? PFFile { userImageFile.getDataInBackgroundWithBlock { (!为imageData:NSData的!错误:NSError) - >虚空中 如果错误== {零如果 imageData中= {零令 图像=的UIImage(数据:为imageData) 自我! profileImage.image = image } } } } – Kobazzo 2014-09-20 13:31:30

+0

这是如何为您解决问题的?我遇到了同样的问题,但这并不能解决问题 – 2015-03-24 01:58:31

相关问题