• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: typeFromFileExtension in Leopard SDK
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: typeFromFileExtension in Leopard SDK


  • Subject: Re: typeFromFileExtension in Leopard SDK
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 14 Apr 2009 06:47:30 -0700

When I did a little work in this area a few weeks ago, I found that just adding a UTI to a document type caused -[NSDocumentController defaultType] to return nil. I posted on this list but no one knew the answer. It might be relevant to your issue...

http://www.cocoabuilder.com/archive/message/cocoa/2009/3/30/233397

Also, I found myself hopelessly confused because it seemed to me that the documentation and method signatures use the same word "type" indiscriminately to mean three different things:

   * Name
   * UTI
   * filename extension

(Now, just so I don't commit the same sin, I define these as the attributes you see in Xcode's Target Inspector > Properties tab, the first three columns, respectively.)

I ended up writing my own little method to get the opposite conversion of what you want. Maybe this will help you write a similar method to for your purposes...

/*!
@brief Returns the first file extension listed in Info.plist for a given
document-type.Name of the current application, or nil if this does not exist.


@details In this context, document-type.Name refers to the attribute shown
as the "Name" column in Xcode's Target inspector > Properties, and is also
what is returned by, for example,
[[NSDocumentController sharedDocumentController] defaultType].
*/
+ (NSString*)fileExtensionForDocumentType:(NSString*)docType ;



+ (NSString*)fileExtensionForDocumentType:(NSString*)docType
{
NSArray* docTypeDics = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDocumentTypes"] ;
NSString* extension = nil ;
for (NSDictionary* docDic in docTypeDics) {
NSString* aDocType = [docDic objectForKey:@"CFBundleTypeName"] ;
if ([aDocType isEqualToString:docType]) {
NSArray* extensions = [docDic objectForKey:@"CFBundleTypeExtensions"] ;
if ([extensions count] > 0) {
extension = [extensions objectAtIndex:0] ;
}


            break ;
        }
    }

    return extension ;
}

_______________________________________________

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


References: 
 >typeFromFileExtension in Leopard SDK (From: Eric Slosser <email@hidden>)
 >Re: typeFromFileExtension in Leopard SDK (From: Kyle Sluder <email@hidden>)
 >Re: typeFromFileExtension in Leopard SDK (From: Eric Slosser <email@hidden>)
 >Re: typeFromFileExtension in Leopard SDK (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Best way to pass large objects between tasks?
  • Next by Date: warning for unsigned parameter, signed argument with NSUInteger
  • Previous by thread: Re: typeFromFileExtension in Leopard SDK
  • Next by thread: Re: typeFromFileExtension in Leopard SDK
  • Index(es):
    • Date
    • Thread