SwiftUTI
A Swift wrapper around Apples Universal Type Identifier functions.
Install / Use
/learn @mkeiser/SwiftUTIREADME
SwiftUTI
A swift wrapper around Apples Universal Type Identifier functions.
Usage
A typical usage might be like that:
let fileURL = URL(fileURLWithPath: ...)
let fileUTI = UTI(withExtension: fileURL.pathExtension)
// Check if it is a specific UTI (UTIs are equatable):
if fileUTI == UTI.pdf {
// handle PDF document...
}
// Check if an UTI conforms to a UTI:
if fileUTI.conforms(to: .image) {
// Handle image file...
}
Creating System and Custom UTIs
All system defined UTTypes are available as static variables. For example, to access the UTType for PDF documents, simply call UTI.pdf.
To define your own UTI (perhaps for your custom document type), you should make an extension like this:
public extension UTI {
static let myDocument = UTI(rawValue: "com.mycompany.mydocument")
}
Your custom type is then accessible like this: UTI.myDocument.
Working with Tags
Initializing from tags:
Initializing an UTI from a file extension:
let fileURL = URL(fileURLWithPath: ...)
let fileUTI = UTI(withExtension: fileURL.pathExtension)
Forcing conformance to another UTI:
let fileURL = URL(fileURLWithPath: ...)
let fileUTI = UTI(withExtension: fileURL.pathExtension, conformingTo: UTI.package)
There are similar APIs to work with MIME types, pasteboard types, and OSTypes.
Accessing tags:
You can easily access tags from any UTI instance. For example to get the MIME type of PDFs, simply call UTI.pdf.mimeType.
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
