Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created March 23, 2019 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylehowells/c6286d77bc4b0462fe46e8fa4ba7bb88 to your computer and use it in GitHub Desktop.
Save kylehowells/c6286d77bc4b0462fe46e8fa4ba7bb88 to your computer and use it in GitHub Desktop.
Print the preferred UTI Document Type for a file extension, then print all possible matching UTI's and their definitions to debug problems.
@import CoreServices;
// All Bundle Ids
NSString *pathExtension = @"db";
NSLog(@"pathExtension: %@", pathExtension);
CFStringRef preferedUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)pathExtension, NULL);
NSLog(@"%@ - Preferred UTI: %@", pathExtension, preferedUTI);
CFDictionaryRef defintion = UTTypeCopyDeclaration(preferedUTI);
NSLog(@"defintion: %@", defintion);
CFArrayRef utisRef = UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)pathExtension, nil);
NSLog(@"UTI: utisRef %@", utisRef);
NSArray *utis = CFBridgingRelease(utisRef);
for (NSString *uti in utis) {
CFDictionaryRef defintion = UTTypeCopyDeclaration((__bridge CFStringRef)uti);
NSDictionary *dict = CFBridgingRelease(defintion);
NSLog(@"defintion: %@", dict);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment