0

I have programmatically fetched the name of the image which i select from the photo library. Is there a way in swift to fetch that image from another view controller without using UIImagePickerController and only using its name programmatically ????

Sample code in swift would definitely help me.

This is the code which i have used to fetch the name of the image selected through UIImgepickerController

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        photoImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
        photoImageView.contentMode = UIViewContentMode.ScaleAspectFill
        photoImageView.clipsToBounds = true
        print("Media info = %@", info)

        if let imageURL = info[UIImagePickerControllerReferenceURL] as? NSURL {
            let result = PHAsset.fetchAssetsWithALAssetURLs([imageURL], options: nil)
            filename = result.firstObject?.filename ?? ""
            print("File name = \(filename)")
        }
}
  • If you have fetched that image name, then you might have get that image too at that place, so store that image in document directory and next time when you want to get that image, get it from document directory. – Wolverine May 26 '16 at 06:06
  • ok. But is there a way to fetch it directly from photo library and not from the documents directory. It can really lower the overheads of saving and getting the image back from documents directory – Ravi Mehta May 26 '16 at 06:26
  • Kindly follow the link http://stackoverflow.com/questions/4314405/how-can-i-get-the-name-of-image-picked-through-photo-library-in-iphone – Goddard May 26 '16 at 09:28
  • then you have to use imagePickerController. – Wolverine May 26 '16 at 09:46
  • @Goddard- That link is about fetching the name of an image recently picked from the photo library using UIImagePickerController. In my case, i have already fetched the name of the picture, i want to know can i fetch the same image from another view controller using only its name and not using UIImagePickerController again ???? – Ravi Mehta May 27 '16 at 08:51

0 Answers0