Created
January 30, 2019 13:06
-
-
Save Denismih/71a8cfa5ee1abc18654549e702769bd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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