Skip to content

Instantly share code, notes, and snippets.

@GE-N
Last active November 11, 2016 07:31
Show Gist options
  • Save GE-N/f02d518f7c133b458f138ab5ae428f3e to your computer and use it in GitHub Desktop.
Save GE-N/f02d518f7c133b458f138ab5ae428f3e to your computer and use it in GitHub Desktop.
import MobileCoreServices
extension String {
func isImageExtension(_ ext: String) -> Bool {
let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext, nil)
guard let imageUTI = uti?.takeRetainedValue() else { return false }
return UTTypeConformsTo(imageUTI, kUTTypeImage)
}
func isImageLink() -> Bool {
let ext = (self as NSString).pathExtension
return isImageExtension(ext)
}
}
"http://www.my-image.com/1.jpg".isImageLink() // true
"http://www.my-image.com/2.jpeg".isImageLink() // true
"http://www.my-image.com/3.png".isImageLink() // true
"http://www.my-image.com/4.tff".isImageLink() // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment