Image extension/format from UIImage in swift
1 min readSep 14, 2020
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.