I have a program for the iPhone that is supposed to be doing intelligent things (picking out appropriate icons for file types) given a list of filenames. I\'m looking for t
Updating the great and accepted answer to Swift 5.3, as an URL extension
extension URL {
var mime: String {
guard
let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil)
else { return "" }
let mime = uti.takeRetainedValue() as String
uti.release()
return mime
}
}