Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Saving and loading?

Saving and loading?
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 30, 2002, 04:59 PM
 
I am having trouble saving a file. I have a single-window app with a controller object. I just want to save a dictionary when the app is quit and load the dictionary in when the app is started. I have implemented the encode/decode methods in all of my custom classes, but I can't figure out how to do the actual save. If I implement a dataRepresentationOfType method, I'm not sure how to indicate the filename. If I implement a writeToFile method, I'm not sure how to actually write the file.

Once I get the appropriate method implemented, can I then just call the method when Quit...is selected and call the loading method in init?

thanks,
kman
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Mar 30, 2002, 05:58 PM
 
NSDocument runs all the save and open panels for you, so you don't need to worry about the filename. All you have to do is implement dataRepresentationOfType.
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Mar 30, 2002, 07:58 PM
 
i guess what you're looking for is this:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[NSArchiver archiveRootObject:whateverObject toFile:[<font color = orange>@"~/Desktop/myFile"</font> stringByExpandingTildeInPath]]
</font>[/code]

or isn't it?
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 30, 2002, 11:43 PM
 
Originally posted by seb2:
<STRONG>i guess what you're looking for is this:

&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
[NSArchiver archiveRootObject:whateverObject toFile:[&lt;font color = orange&gt;@"~/Desktop/myFile"&lt;/font&gt; stringByExpandingTildeInPath]]
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/BLOCKQUOTE&gt;

or isn't it?</STRONG>
This worked beautifully. Thank you. I'm having some problems getting it to save on quit, however. I redirected the terminate: method to connect with my controller class, but this pretty much wiped out the ability of the app to quit (other than saving my file!). Is there a way for me to add my line of code to the built in terminate method:? Do I have to subclass NSApplication and add my line to that terminate: method?

kman
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Mar 31, 2002, 03:39 AM
 
I don't know about modifying the terminate method but you could perhaps just override the dealloc method in your document class and have it handle saving for you, then do a [super dealloc].

Another option is to make your document object the delegate for NSApplication and then implement applicationWillTerminate in your document object and handle saving there. Your document will be sent the applicationWillTerminate message immediately before the application terminates.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:28 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2