 |
 |
Saving and loading?
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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
|
|
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?
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
Originally posted by seb2:
<STRONG>i guess what you're looking for is this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre>& amp;lt;font size=1 face=courier>
[NSArchiver archiveRootObject:whateverObject toFile:[<font color = orange>@"~/Desktop/myFile"</font> stringByExpandingTildeInPath]]
</font></pre><HR></BLOCKQUOTE>
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
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |