Search code examples
objective-ccocoansimageuti

Human-readable strings for [NSImage imageTypes] identifiers?


Put simply, how does one retrieve a human-readable string (for instance, "Portable Network Graphics") for the type of identifier found in the array returned by [NSImage imageTypes] (for instance, "public.png" or "com.microsoft.bitmap")? I've read through the various pieces of documentation for universal type identifiers, but couldn't find anything. Am I barking up the wrong tree?


Solution

  • I think UTTypeCopyDescription() does what you're looking for:

    NSArray *types = [NSImage imageTypes];
    for (NSString *type in types) {
        NSString *desc = (NSString *)UTTypeCopyDescription((CFStringRef)type);
        NSLog(@"description for %@: %@", type, desc);
        [desc release];
    }
    

    Output:

    description for com.adobe.pdf: Portable Document Format (PDF)
    description for com.apple.pict: QuickDraw picture
    description for com.adobe.encapsulated-postscript: Encapsulated PostScript
    description for public.jpeg: JPEG image
    description for public.png: Portable Network Graphics image
    description for com.compuserve.gif: Graphics Interchange Format (GIF)
    description for public.jpeg-2000: JPEG 2000 image
    description for com.canon.tif-raw-image: Canon TIF raw image
    description for com.adobe.raw-image: Adobe raw image
    etc....