On 3, Jan, 2012, at 09:42 AM, Quincey Morris wrote:

> 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."

Oops. Completely missed that. Even after reading your post it took me a while 
to see it. Probably time for another coffee.

> 
> 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:'?

Thanks! I didn't know about this NSWorkspace method. I think a google search 
got me to the solution I was using. 

Anyway, thanks, I'll try the NSWorkspace method.

Cheers,

Martin


> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
    Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: [email protected]
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to