Last active
December 24, 2023 15:38
-
-
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/
This file contains hidden or 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
//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
do I need to add something in info.plist?