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 Document-Based App With Two Arrays

Saving Document-Based App With Two Arrays
Thread Tools
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 5, 2003, 12:29 AM
 
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.

work: maczealots blog: carpeaqua
     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Apr 5, 2003, 02:06 AM
 
A really simple way of doing it: Put both arrays in a dictionary, and save _that_ to a file.
[vash:~] banana% killall killall
Terminated
     
tikki  (op)
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 5, 2003, 02:11 AM
 
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?

work: maczealots blog: carpeaqua
     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Apr 5, 2003, 05:48 AM
 
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
Reply With Quote
Apr 5, 2003, 09:00 AM
 
You could also use:

+ dictionaryWithContentsOfFile:

and

- writeToFile:atomically:

if you don't feel like getting the NSData from the file by hand.
     
tikki  (op)
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 5, 2003, 03:46 PM
 
Awesome. Got it working. Thanks

work: maczealots blog: carpeaqua
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 8, 2003, 10:23 AM
 
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
Reply With Quote
Apr 9, 2003, 03:17 PM
 
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. )
     
tikki  (op)
Mac Elite
Join Date: Jan 2003
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 9, 2003, 09:05 PM
 
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.

work: maczealots blog: carpeaqua
     
   
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 03:21 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