Created
January 24, 2018 09:50
-
-
Save daehn/b8849171c34ed964cca99c5d2a1205d4 to your computer and use it in GitHub Desktop.
This file contains 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
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