我試圖通過下面的代碼獲取圖像文件。解析PFFile錯誤 - 試圖獲取圖像文件(Swift2)
let anotherPhoto : PFObject = PFObject(className: "Menu")
let userImageFile = anotherPhoto["photo"] as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
}
}
}
,但它總是會發生這種錯誤
fatal error: unexpectedly found nil while unwrapping an Opcional value
此錯誤出現在該行
let userImageFile = anotherPhoto["photo"] as! PFFile
有什麼不對的代碼?
您實際上沒有從Parse中檢索到'anotherPhoto',所以對象將是空的。這意味着'照片'鍵將是零,但你說'as! PFFile' - as!說「這個價值不會是零」。所以你得到一個異常 – Paulw11
哦!我懂了!但我如何檢索其他照片?使用PFQuery? @ Paulw11 –
是的。查詢或獲取操作 – Paulw11