如何快速获取从图库中选择的图像路径

问题描述:

在使用图像选择器的 obj-c 中,我可以获得图像的路径:

In obj-c with using image picker, I could get path of image with this:

NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];

但是当我在 swift 中尝试这段代码时:

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
... }

它崩溃并说

fatal error: unexpectedly found nil while unwrapping an Optional value

那么,如何快速获取图像的路径?

so, how can I get path of an image in swift?

我使用下面的代码得到了图片网址.它在 swift 2.0 中工作正常

hi i got the image url using below code .It works fine in swift 2.0

let path =editingInfo[UIImagePickerControllerReferenceURL] as!NSURL

let path = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL