由于一些奇怪的原因,我在尝试将PFFile保存到Parse时不断崩溃。我知道有一个图像,因为passengerPhoto正在设置它,而imageData正在设置,因为我在控制台中打印它。问题是当它到达这一行时。
profileImg!.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) in
if success {
}
})
我收到错误"致命错误:在展开可选值时意外发现nil"如果设置了passengerPhoto并且打印了imageData,我还不清楚如果有imageData,profileImg是如何为零的。
完整代码:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
self.passengerPhoto.image = image
let imageData = UIImagePNGRepresentation(image)!
let profileImg = PFFile(data: imageData)
profileImg!.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) in
if success {
self.passengerPhoto.image = image
}
})
}