我是代码新手,我不知道如何在这里删除我的可选值。我在某处读到这可能是我的问题。任何帮助都会很棒!
我一直在关注这个教程:https://www.youtube.com/watch?v=Qyy8pJd4IWU
@IBAction func dropPhoto(sender: AnyObject) {
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [NSObject : AnyObject]?) {
self.dismissViewControllerAnimated(true, completion: nil)
let thumbnail = image.resizedImageWithContentMode(UIViewContentMode.ScaleAspectFit, bounds: CGSizeMake(400, 400), interpolationQuality: CGInterpolationQuality.High)
let imgData = UIImagePNGRepresentation(thumbnail)
let base64EncodedImage = imgData?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions())
let uniqueReference = firebase?.childByAutoId()
uniqueReference!.setValue(base64EncodedImage)
let key = uniqueReference?.key
_ = mapView.userLocation.location
geofire!.setLocation(mapView.userLocation.location,forKey: key)
}
最佳答案
每当您看到此错误时,请查找“!”
这里有两行包含强制展开
geofire!.setLocation(mapView.userLocation.location,forKey: key)
和
uniqueReference!.setValue(base64EncodedImage)
您应该能够通过简单地替换 !与一个? ,例如
geofire?.setLocation(mapView.userLocation.location,forKey: key)
只有当 geoFire 是一个真实值时,才会调用 setLocation,否则如果你还想处理 nil 情况,快速的方法是:
if let geoFire = geoFire {
geoFire.setLocation(mapView.userLocation.location, forKey: key)
}
else{
*do something*
}
关于xcode - fatal error : unexpectedly found nil while unwrapping an Optional value (lldb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35885678/