Skip to content

Instantly share code, notes, and snippets.

Created Jan 24, 2018
What would you like to do?
import Foundation
import MobileCoreServices
struct UTType: CustomStringConvertible {
let value: CFString
init?(mimeType: String) {
guard let UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType as CFString, nil)?.takeUnretainedValue() else { return nil }
value = UTI
var description: String {
return value as String
extension UTType {
var isImage: Bool {
return UTTypeConformsTo(value, kUTTypeImage)
var isSVG: Bool {
return UTTypeConformsTo(value, kUTTypeScalableVectorGraphics)
let image = UTType(mimeType: "image/jpg")
image?.isImage // true
image?.isSVG // false
let svg = UTType(mimeType: "image/svg+xml")
svg?.isImage // true
svg?.isSVG // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment