Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save file with mac application - file extension

I have a little question, I try to understand how to save a file with Cocoa for a Mac application, I understand that I can save it with a Save Panel.

Here is a great example: Saving files in cocoa

Now my question is, is there a way to save the document (a plst file) with a my extension (eg. *.fun, *.xxx, *.myextension, ecc...)? I want to be able to open my application when the user double clicks on the file.

like image 538
francesco.venica Avatar asked Jul 22 '11 09:07

francesco.venica


1 Answers

Set the accepted document types in your application's plist; something like this:

Make "yourExtension" whatever you want your extension to be without the period.

But once you've done that, it's up to you to figure out how to load them upon opening. That's where NSDocument and friends come in. Look into how a document-based application functions. Here's some Apple documentation on the subject.

If you want to see it in action check the source for TextEdit in /Developer/Examples. Plus, if you don't mind migrating the progress you have, Xcode has a template for a document-based application (Create a new project and select the checkbox titled "Create Document Based Application".)

like image 95
Isabel Avatar answered Nov 07 '22 07:11

Isabel