Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using UTType in Swift in Xcode 12 and iOS 14
//https://emptytheory.com/2020/09/29/better-uniform-type-identifiers-with-xcode-12/
import UniformTypeIdentifiers
//Show UTType properties for built-in type
UTType.pdf.printInfo()
//Show properties for looked up type
UTType.word.printInfo()
extension UTType {
/// Show some properties on the UTType
func printInfo() {
print("MIME type: \(preferredMIMEType ?? "No MIME Type")")
print("File Extension: \(preferredFilenameExtension ?? "No extension")")
print("Tags: \(tags)")
print("Identifier: \(identifier)")
}
static var word: UTType {
UTType.types(tag: "docx", tagClass: .filenameExtension, conformingTo: nil).first!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.