Skip to content

Instantly share code, notes, and snippets.

@emptyfuel
Last active December 24, 2023 15:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emptyfuel/8502a3e1c43658664c34c27e2e31fd8c to your computer and use it in GitHub Desktop.
Save emptyfuel/8502a3e1c43658664c34c27e2e31fd8c to your computer and use it in GitHub Desktop.
Using UTType in Swift in Xcode 12 and iOS 14 related code from blog post on emptytheory.com at https://emptytheory.com/2020/09/29/better-uniform-type-identifiers-with-xcode-12/
//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!
}
}
@trial
Copy link

trial commented Apr 7, 2022

do I need to add something in info.plist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment