Image extension/format from UIImage in swift

If you want to restrict the user to select only particular UIImage format such as JPEG, PNG , JPG.

You can use one condition inside this imagePickerController() function,

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
let assetPath = info[UIImagePickerControllerReferenceURL] as! NSURL
if (assetPath.absoluteString?.hasSuffix("JPG"))! {
print("This is JPG Image")
}
else if (assetPath.absoluteString?.hasSuffix("PNG"))! {
print("This is PNG Image")
}
else if (assetPath.absoluteString?.hasSuffix("GIF"))! {
print("This is GIF Image")
}
else {
print("Other Formats are not allowed like .tiff , .gif")
}
}

Thanks.

--

--

iOS Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store