Re: [Array writeToFile:Path atomically:YES]
Re: [Array writeToFile:Path atomically:YES]
- Subject: Re: [Array writeToFile:Path atomically:YES]
- From: Allan Odgaard <email@hidden>
- Date: Wed, 12 May 2004 04:21:20 +0200
On 12. May 2004, at 4:09, David Blanton wrote:
Maybe I don't understand arrays well enough. To create an array of n
rows
and m columns I do the following:
Rows? Columns?
Then I make a new KillList object, set the ivars and add the KillList
object
to the array. It is this array that I want to write to a file so I
can read
it back and load an array when the program starts.
So, what is the Cocoa way to do this?
Use an NSDictionary instead of your own KillList object. E.g.:
NSMutableArray* array = [NSMutableArray array];
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dictionary setObject:@"shadow" forKey:@"user"];
[dictionary setObject:@"the4seasons" forKey:@"password"];
[array addObject:dict];
[array writeToFile:@"/tmp/test.dict", atomically:NO];
There is unfortunately no way to extend the current "writeToFile:"
process to handle custom objects. For this you need to use an archiver
(but then you won't get a nice xml file).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.