0

I am newbie in swift i stuck in a little problem. I am attaching image using UIImagePickerController. Good thing is that successfully attached an image but unable to get attached file name. I tried several solutions like

UIImagePickerControllerImageURL, UIImagePickerControllerImageRefrenceURL,
UIImagePickerControllerPHAsset but didn't succeeded Please guide me and thanks in advance

Ahmad Qasim
  • 452
  • 1
  • 8
  • 26

1 Answers1

1

As per your question, you will get your point in the didFinishPickingMediaWithInfo method , where you get info object in above method in that included all info about your file.

Check below code:

let imageURL = info[UIImagePickerControllerImageURL] as! URL
print(imageURL.lastPathComponent)

Happy coding.

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
Mauli
  • 71
  • 2
  • thanks for answer tried it but lastPathComponent gives some id related to image not the name of image this method not gives any satisfying output – Ahmad Qasim Sep 07 '18 at 08:49
  • you will get name by this info only . checkout this, if let path = info[UIImagePickerControllerReferenceURL] as? NSURL { let url = path.absoluteString //Continue whatever you want let componentString = (url )?.components(separatedBy: "&ext=") – Mauli Sep 07 '18 at 09:04