 |
 |
Saving Document-Based App With Two Arrays
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status:
Offline
|
|
Greetings,
I have a document-based application with two NSMutableArrays (each populating their own respective table).
Using tutorials I found on the internet & my library of Cocoa books, I have gotten it to save my main table's array, but am clueless how to get application to save both of my arrays to the same file.
Can anyone give me some direction on how to get this done? Are there any tutorials or examples online?
Help is appreciated.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
A really simple way of doing it: Put both arrays in a dictionary, and save _that_ to a file.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status:
Offline
|
|
Originally posted by Gul Banana:
A really simple way of doing it: Put both arrays in a dictionary, and save _that_ to a file.
Would I just set up the Mutabledictionary in these methods?
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
And then write/load the dictionary there, or is it a broader scope than just those two methods?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
Those two methods are all you need to worry about.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2000
Location: UK
Status:
Offline
|
|
You could also use:
+ dictionaryWithContentsOfFile:
and
- writeToFile:atomically:
if you don't feel like getting the NSData from the file by hand.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status:
Offline
|
|
Awesome. Got it working. Thanks 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
You can also use Keyed Archiving (new to 10.2). Keyed archiving has some advantages or "normal" archiving. Apple has some info on there developer site under the Cocoa Documentation. Look under Archiving ans Serialization. I believe the examples now use Keyed Archiving. Also Stepwise, http://www.stepwise.com, has an excellent article that takes you through step-by-step. It is taking from Bill Cheeseman's book, Cocoa Recipes for Mac OS X. The link is under the "more articles..." link. For the impatient it is http://www.stepwise.com/Articles/Ver...rchiving.html.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Status:
Offline
|
|
tikki, how'd you get it to work? I'm in a similar situation. I'm not sure, but so far i have:
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSDictionary *list =[list initWithObjects:_german forKeys:_english];
}
( _german and _english being two arrays)
Now do I get the dictionary to display itself as a NSData so it can be returned. (that is what i have to do right? 8^/ ) Also, how do I extract the dictionary from the NSData in the loadDataRepresentation: method?
(Last edited by Spiffster; Apr 9, 2003 at 03:29 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status:
Offline
|
|
Originally posted by Spiffster:
tikki, how'd you get it to work? I'm in a similar situation. I'm not sure, but so far i have:
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSDictionary *list =[list initWithObjects:_german forKeys:_english];
}
( _german and _english being two arrays)
Now do I get the dictionary to display itself as a NSData so it can be returned. (that is what i have to do right? 8^/ ) Also, how do I extract the dictionary from the NSData in the loadDataRepresentation: method?
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
[tableView deselectAll:nil];
dataStuff = [[NSMutableDictionary alloc] init];
[dataStuff setObject:assignmentList forKey:@"assignmentListKey"];
[dataStuff setObject:gradeList forKey:@"gradeListKey"];
return [NSArchiver archivedDataWithRootObject:dataStuff];
}
datastuff being my nsmutabledictionary.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|