• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Array writeToFile:Path atomically:YES]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: [Array writeToFile:Path atomically:YES] (From: David Blanton <email@hidden>)

  • Prev by Date: Re: [Array writeToFile:Path atomically:YES]
  • Next by Date: Building Static Libraries Linked To Frameworks
  • Previous by thread: Re: [Array writeToFile:Path atomically:YES]
  • Next by thread: Re: [Array writeToFile:Path atomically:YES]
  • Index(es):
    • Date
    • Thread