Determining UTIs from File Extensions

The Mobile Core Services module offers utilities that enable you to retrieve UTI information based on file extensions. Be sure to import the module when using these C-based functions. The following function returns a preferred UTI when passed a path extension string. The preferred identifier is a single UTI string:

@import MobileCoreServices; NSString *preferredUTIForExtension(NSString *ext) {     // Request the UTI for the file extension     NSString *theUTI = (__bridge_transfer NSString *)         UTTypeCreatePreferredIdentifierForTag(             kUTTagClassFilenameExtension,            (__bridge CFStringRef) ext, NULL);     return theUTI; }

You can pass a MIME type instead ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.