Skip to content

Instantly share code, notes, and snippets.

@Denismih
Created January 30, 2019 13:06
Show Gist options
  • Save Denismih/71a8cfa5ee1abc18654549e702769bd0 to your computer and use it in GitHub Desktop.
Save Denismih/71a8cfa5ee1abc18654549e702769bd0 to your computer and use it in GitHub Desktop.
import MobileCoreServices
func mimeTypeForPath(path: String) -> String {
let url = NSURL(fileURLWithPath: path)
let pathExtension = url.pathExtension
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() {
if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
return mimetype as String
}
}
return "application/octet-stream"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment