Reputation: 3374
In obj-c with using image picker, I could get path of image with this:
NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
but when I try this code in swift :
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
var path : NSURL = editingInfo.valueForKeyPath("UIImagePickerControllerOriginalImage") as NSURL
... }
it crashes and say
fatal error: unexpectedly found nil while unwrapping an Optional value
so, how can I get path of an image in swift?
Upvotes: 1
Views: 4388
Reputation: 323
hi i got the image url using below code .It works fine in swift 2.0
let path = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL
Upvotes: 2
Reputation: 21
you lost this line?
imagePicker.allowsEditing = true
if you set
imagePicker.allowsEditing = false
editingInfo will always be nil
Upvotes: 2
Reputation: 80265
You are perhaps using a different dictionary? Above it is info
, later you are using editingInfo
. Explain how you extract your dictionaries with complete code.
Upvotes: 0