Last active
May 9, 2019 01:30
-
-
Save zwaldowski/2360184657889727a58aa442faf1fdf2 to your computer and use it in GitHub Desktop.
MobileCoreServices Swift audit
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
let swift = UTType.swiftSource | |
print(swift) // => Swift Source Code | |
print(swift.rawValue) // public.swift-source | |
print(swift.conforms(to: .sourceCode)) // => true | |
print(swift.declaration?[.conformsTo] as Any) // [ "public.source-code" ] | |
print(swift.declaringBundleURL as Any) // => /System/Library/CoreServices/MobileCoreTypes.bundle | |
print(swift.isDeclared) // => true | |
print(swift.isDynamic) // => false | |
print(swift.preferredTag(for: .filenameExtension) as Any) // => "swift" | |
print(UTType(preferredTag: "swift", for: .filenameExtension, conformingTo: nil) == swift) // => "true" | |
// MARK: - Extension | |
extension UTType: CustomStringConvertible { | |
static let markdown = UTType("net.daringfireball.markdown") | |
@available(iOS 11.0, *) | |
static let HEIF = UTType("public.heif") | |
} | |
// MARK: - Fluent URLs | |
extension URL { | |
mutating func appendPathExtension(for uti: UTType) { | |
guard let pathExtension = uti.preferredTag(for: .filenameExtension) else { return } | |
appendPathExtension(pathExtension) | |
} | |
} | |
let documentsURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | |
var destinationURL = documentsURL | |
destinationURL.appendPathComponent("best-photo") | |
destinationURL.appendPathExtension(for: .HEIF) | |
print(destinationURL) // => file:///var/mobile/data/Containers/Data/Application/C7A23B13-F375-4BDD-9586-25D93DCDB413/Documents/best-photo.heif | |
// MARK: - Interacting with non-audited APIs | |
let bestLanguages: [UTType] = [ .swiftSource, .javascript, .assemblyLanguageSource ] | |
let bestLanguagesForCocoa = bestLanguages as NSArray | |
print(bestLanguagesForCocoa) // => [ "public.swift-source", "com.netscape.javascript-source," "public.assembly-source" ] | |
print(type(of: bestLanguagesForCocoa[0] as! NSObject)) // => __NSCFConstantString | |
// MARK: - |
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
SWIFT_INCLUDE_PATHS = $(SRCROOT)/Modules |
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
// This must go at Modules/MobileCoreServices/module.modulemap | |
module MobileCoreServices { | |
header "MobileCoreServicesSwift.h" | |
link framework "MobileCoreServices" | |
requires swift | |
} |
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
// This must go at Modules/MobileCoreServices/MobileCoreServicesSwift.h | |
@import Foundation; | |
typedef NSString *UTType NS_TYPED_EXTENSIBLE_ENUM; | |
typedef NSString *UTTypeDefinitionKey NS_TYPED_EXTENSIBLE_ENUM; | |
typedef NSString *UTTagClass NS_TYPED_ENUM; | |
#import <MobileCoreServices/UTType.h> | |
#import <MobileCoreServices/UTCoreTypes.h> | |
NS_INLINE _Nullable UTType __UTTypeCreatePreferredIdentifierForTag2(NSString *_Nonnull tag, _Nonnull UTTagClass tagClass, _Nullable UTType conformingToUTI) { | |
return (__bridge_transfer UTType)UTTypeCreatePreferredIdentifierForTag((__bridge CFStringRef)tagClass, (__bridge CFStringRef)tag, (__bridge CFStringRef)conformingToUTI); | |
} | |
NS_INLINE NSArray <UTType> *_Nonnull __UTTypeCreateAllIdentifiersForTag2(NSString *_Nonnull tag, _Nonnull UTTagClass tagClass, _Nullable UTType conformingToUTI) { | |
return ((__bridge_transfer NSArray *)UTTypeCreateAllIdentifiersForTag((__bridge CFStringRef)tagClass, (__bridge CFStringRef)tag, (__bridge CFStringRef)conformingToUTI)) ?: @[]; | |
} |
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
// This must go at Modules/MobileCoreServices/MobileCoreServices.apinotes | |
Name: MobileCoreServices | |
Functions: | |
- Name: UTTypeCreatePreferredIdentifierForTag | |
Availability: nonswift | |
- Name: __UTTypeCreatePreferredIdentifierForTag2 | |
SwiftName: 'UTType.init(preferredTag:for:conformingTo:)' | |
- Name: UTTypeCreateAllIdentifiersForTag | |
Availability: nonswift | |
- Name: __UTTypeCreateAllIdentifiersForTag2 | |
SwiftName: 'UTType.all(tag:for:conformingTo:)' | |
- Name: UTTypeCopyPreferredTagWithClass | |
ResultType: 'NSString *_Nullable' | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
- Position: 1 | |
Type: 'UTTagClass _Nonnull' | |
SwiftName: 'UTType.preferredTag(self:for:)' | |
- Name: UTTypeCopyAllTagsWithClass | |
ResultType: 'NSArray <UTType> *_Nullable' | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
- Position: 1 | |
Type: 'UTTagClass _Nonnull' | |
SwiftName: 'UTType.allTags(self:for:)' | |
- Name: UTTypeEqual | |
Availability: nonswift | |
- Name: UTTypeConformsTo | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
- Position: 1 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'UTType.conforms(self:to:)' | |
- Name: UTTypeCopyDescription | |
ResultType: 'NSString *_Nonnull' | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'getter:UTType.description(self:)' | |
- Name: UTTypeIsDeclared | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'getter:UTType.isDeclared(self:)' | |
- Name: UTTypeIsDynamic | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'getter:UTType.isDynamic(self:)' | |
- Name: UTTypeCopyDeclaration | |
ResultType: 'NSDictionary <UTTypeDefinitionKey, id> *_Nullable' | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'getter:UTType.declaration(self:)' | |
- Name: UTTypeCopyDeclaringBundleURL | |
ResultType: 'NSURL *_Nullable' | |
Parameters: | |
- Position: 0 | |
Type: 'UTType _Nonnull' | |
SwiftName: 'getter:UTType.declaringBundleURL(self:)' | |
- Name: UTCreateStringForOSType | |
Availability: nonswift | |
- Name: UTGetOSTypeFromString | |
Availability: nonswift | |
Globals: | |
- Name: kUTTypeIdentifierKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: 'UTTypeDefinitionKey.identifier' | |
- Name: kUTTypeTagSpecificationKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: tagSpecification | |
- Name: kUTTypeConformsToKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: conformsTo | |
- Name: kUTTypeDescriptionKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: description | |
- Name: kUTTypeIconFileKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: iconFile | |
- Name: kUTTypeReferenceURLKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: referenceURL | |
- Name: kUTTypeVersionKey | |
Type: 'const UTTypeDefinitionKey _Nonnull' | |
SwiftName: version | |
- Name: kUTTagClassFilenameExtension | |
Type: 'const UTTagClass _Nonnull' | |
- Name: kUTTagClassMIMEType | |
Type: 'const UTTagClass _Nonnull' | |
- Name: kUTTagClassNSPboardType | |
Type: 'const UTTagClass _Nonnull' | |
- Name: kUTTagClassOSType | |
Type: 'const UTTagClass _Nonnull' | |
- Name: kUTTypeItem | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeContent | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCompositeContent | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMessage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeContact | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeArchive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeDiskImage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeData | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeDirectory | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeResolvable | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSymLink | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeExecutable | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMountPoint | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAliasFile | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAliasRecord | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeURLBookmarkData | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeURL | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeFileURL | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePlainText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeUTF8PlainText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeUTF16ExternalPlainText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeUTF16PlainText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeDelimitedText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCommaSeparatedText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeTabSeparatedText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeUTF8TabSeparatedText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeRTF | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeHTML | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeXML | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSourceCode | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAssemblyLanguageSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeObjectiveCSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSwiftSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCPlusPlusSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeObjectiveCPlusPlusSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCHeader | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCPlusPlusHeader | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJavaSource | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAppleScript | |
Type: 'const UTType _Nonnull' | |
SwiftName: 'UTType.applescript' | |
- Name: kUTTypeOSAScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeOSAScriptBundle | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJavaScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeShellScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePerlScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePythonScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeRubyScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePHPScript | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJSON | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePropertyList | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeXMLPropertyList | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeBinaryPropertyList | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePDF | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeRTFD | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeFlatRTFD | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeTXNTextAndMultimediaData | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeWebArchive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeImage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJPEG | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJPEG2000 | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeTIFF | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePICT | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeGIF | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePNG | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeQuickTimeImage | |
Type: 'const UTType _Nonnull' | |
SwiftName: 'UTType.quicktimeImage' | |
- Name: kUTTypeAppleICNS | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeBMP | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeICO | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeRawImage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeScalableVectorGraphics | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeLivePhoto | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAudiovisualContent | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMovie | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeVideo | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAudio | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeQuickTimeMovie | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMPEG | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMPEG2Video | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMPEG2TransportStream | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMP3 | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMPEG4 | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMPEG4Audio | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAppleProtectedMPEG4Audio | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAppleProtectedMPEG4Video | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAVIMovie | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeAudioInterchangeFileFormat | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeWaveformAudio | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeMIDIAudio | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePlaylist | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeM3UPlaylist | |
Type: 'const UTType _Nonnull' | |
SwiftName: 'UTType.m3uPlaylist' | |
- Name: kUTTypeFolder | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeVolume | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePackage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeBundle | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePluginBundle | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSpotlightImporter | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeQuickLookGenerator | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeXPCService | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeFramework | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeApplication | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeApplicationBundle | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeApplicationFile | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeUnixExecutable | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeWindowsExecutable | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJavaClass | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeJavaArchive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSystemPreferencesPane | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeGNUZipArchive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeBzip2Archive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeZipArchive | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeSpreadsheet | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypePresentation | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeDatabase | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeVCard | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeToDoItem | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeCalendarEvent | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeEmailMessage | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeInternetLocation | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeInkText | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeFont | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeBookmark | |
Type: 'const UTType _Nonnull' | |
- Name: kUTType3DContent | |
Type: 'const UTType _Nonnull' | |
SwiftName: 'UTType.sceneContent' | |
- Name: kUTTypePKCS12 | |
Type: 'const UTType _Nonnull' | |
SwiftName: 'UTType.pkcs12' | |
- Name: kUTTypeX509Certificate | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeElectronicPublication | |
Type: 'const UTType _Nonnull' | |
- Name: kUTTypeLog | |
Type: 'const UTType _Nonnull' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment