-
Notifications
You must be signed in to change notification settings - Fork 1
/
MobileCoreServices+Convenience.m
41 lines (28 loc) · 1.34 KB
/
MobileCoreServices+Convenience.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// MobileCoreServices+Convenience.m
// Offcloud
//
// Created by Alexander Ivanov on 23.02.17.
// Copyright © 2017 Alexander Ivanov. All rights reserved.
//
#import "MobileCoreServices+Convenience.h"
@implementation UTUniformType
+ (NSString *)preferredTagWithClass:(CFStringRef)outTagClass fromTag:(NSString *)inTag withClass:(CFStringRef)inTagClass {
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(inTagClass, (__bridge CFStringRef)inTag, NULL);
CFStringRef outTag = UTTypeCopyPreferredTagWithClass(uti, outTagClass);
CFRelease(uti);
return (NSString *)CFBridgingRelease(outTag);
}
+ (NSArray *)allTagsWithClass:(CFStringRef)outTagClass fromTag:(NSString *)inTag withClass:(CFStringRef)inTagClass {
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(inTagClass, (__bridge CFStringRef)inTag, NULL);
CFArrayRef outTag = UTTypeCopyAllTagsWithClass(uti, outTagClass);
CFRelease(uti);
return (NSArray *)CFBridgingRelease(outTag);
}
+ (NSString *)mimeTypeFromFilenameExtension:(NSString *)filenameExtension {
return [self preferredTagWithClass:kUTTagClassMIMEType fromTag:filenameExtension withClass:kUTTagClassFilenameExtension];
}
+ (NSArray<NSString *> *)filenameExtensionsFromMimeType:(NSString *)mimeType {
return [self allTagsWithClass:kUTTagClassFilenameExtension fromTag:mimeType withClass:kUTTagClassMIMEType];
}
@end