• 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: Best Practices for Associating a File Extension With a File in XCode 4?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best Practices for Associating a File Extension With a File in XCode 4?


  • Subject: Re: Best Practices for Associating a File Extension With a File in XCode 4?
  • From: Vik Rubenfeld <email@hidden>
  • Date: Sat, 03 Sep 2011 17:14:26 -0700

Thanks very much for this info. I've been coding in Cocoa all year, but I'm still a newbie to plenty of stuff, including this.

I have developed code that does permit me to append the file extension to the filename:

- (IBAction) saveDocumentAs:(id)sender
{
    NSSavePanel* theSavePanel = [[NSSavePanel alloc]init];
    [theSavePanel setDirectory:[path stringByExpandingTildeInPath]];
    [theSavePanel setPrompt:NSLocalizedString(@"Save",nil)];
    [theSavePanel setRequiredFileType:DESIREDFILEEXTENSION];

     //adapted in part from code in an Apple demo app
     void (^theSavePanelHandler)(NSInteger) = ^( NSInteger result )
     {
          NSURL *theDirectoryURL = [theSavePanel directoryURL];
        NSString *theDirectoryPath = [theSavePanel directory];
        NSString* theFilename = [theSavePanel filename];

          if( theDirectoryURL )
          {
               if( theDirectoryPath )
               {
                    fileName =  theFilename;

                NSMutableArray* items = [NSMutableArray array];
                //Here's where your app stores its data - of a type for which encodeWithCoder has been implemented -
                //in an NSMutableArray or other data structure accepted by NSKeyedArchiver
                [NSKeyedArchiver archiveRootObject: items toFile: theFilename];
               } // if
          } // if
     };

     [theSavePanel beginSheetModalForWindow: editorWindow
                                 completionHandler:theSavePanelHandler];
}

That seems to work quite well.  After developing that code, I learned about the NSDocument method:

[self saveDocumentWithDelegate:self didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) contextInfo:nil];

If I'm using saveDocumentWithDelegate:didSaveSelector:contextInfo, what is the correct way for me to communicate the list of suitable extensions to the Save panel?




On Sep 3, 2011, at 3:33 PM, Quincey Morris wrote:

> On Sep 3, 2011, at 15:21 , Vik Rubenfeld wrote:
>
>> I went to the XCode App Properties panel and added an Exported UTI with file extension of "CAQuickLook". However, saving the document, still does not append a file extension to the file name.
>>
>> What am I missing?
>
> You're not missing anything. Saving a document does not append a file extension to the file name.
>
> You must provide the full file name, which includes the extension. Typically, it gets the correct extension because the user is presented with a Save panel, and *that* returns a file name to you with a suitable extension in place already.
>
> The Save panel gets the list of suitable extensions (and the default extension within that list) from the document types that you've set up for the app in Xcode.
>
>

_______________________________________________

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

  • Follow-Ups:
    • Re: Best Practices for Associating a File Extension With a File in XCode 4?
      • From: Kyle Sluder <email@hidden>
References: 
 >Re: Best Practices for Associating a File Extension With a File in XCode 4? (From: Lee Ann Rucker <email@hidden>)
 >Re: Best Practices for Associating a File Extension With a File in XCode 4? (From: Vik Rubenfeld <email@hidden>)
 >Re: Best Practices for Associating a File Extension With a File in XCode 4? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Best Practices for Associating a File Extension With a File in XCode 4?
  • Next by Date: Re: Best Practices for Associating a File Extension With a File in XCode 4?
  • Previous by thread: Re: Best Practices for Associating a File Extension With a File in XCode 4?
  • Next by thread: Re: Best Practices for Associating a File Extension With a File in XCode 4?
  • Index(es):
    • Date
    • Thread