Re: File UTI on 10.6.8
Re: File UTI on 10.6.8
- Subject: Re: File UTI on 10.6.8
- From: Quincey Morris <email@hidden>
- Date: Tue, 03 Jan 2012 00:42:31 -0800
On Jan 2, 2012, at 23:57 , Martin Hewitson wrote:
> I want to check if a file extension is registered as a text file. So I made a little category method on NSString like this:
>
> - (BOOL)isText
> {
> BOOL fileIsText = NO;
>
> CFStringRef fileExtension = (CFStringRef) self;
> CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
> if (UTTypeConformsTo(fileUTI, kUTTypeText)) {
> fileIsText = YES;
> }
> CFRelease(fileUTI);
>
> return fileIsText;
> }
>
> This works fine on 10.7. On 10.6.8 when
>
> self = @"tex"
>
> this returns NO and fileUTI is dyn.age81k3p2.
>
> Anybody got an idea what this dyn.* means?
Well, you don't need to ask *us* when the answer in the the documentation for the 'UTTypeCreatePreferredIdentifierForTag' function:
> "If no result is found, this function creates a dynamic type beginning with the dyn prefix. This allows you to pass the UTI around and convert it back to the original tag."
OTOH, I doubt that you really want to *create* a UTI just to test conformance, especially since you immediately discard the created UTI. What's wrong with using one of the NSWorkspace methods, such as 'filenameExtension:isValidForType:'?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden