Re: using NSMutableDictionary in place of NSDictionary
Re: using NSMutableDictionary in place of NSDictionary
- Subject: Re: using NSMutableDictionary in place of NSDictionary
- From: Scott Anguish <email@hidden>
- Date: Sat, 25 Feb 2006 02:25:50 -0500
On Feb 24, 2006, at 2:36 PM, Steve Sheets wrote:
To read/write to File:
a_dictionary = [NSDictionary
dictionaryWithContentsOfFile:a_file_name]; // read file
[a_dictionary writeToFile:a_file_name atomically:YES]; // write file
To read/write to Defaults
a_dictionary = [[NSUserDeafaults standardUserDefaults]
dictionaryForKey:a_key]; // read defaults
[[NSUserDeafaults standardUserDefaults] setObject: a_dictionary
forKey:a_key]; // write defaults
In both these cases the dictionary objects are not freeze-dried, but
they are written out as text representation that can be read again
later (plist format)... so you'll get back a root object of whatever
type of class you tell to read the file
We were concerned that some of this encoding/decoding would
actually check what type of object was being written, and want
explicitly an NSDictionary object. For example, if we save a
NSMutableDictionary using User Defaults, would it return as
NSDictionary or NSMutableDictionary? The actual data is stored as
XML plist, so we thought it would be ok, but the documentation
ALWAYS talks about using NSDictionary in the calls, never
mentioning NSMutableDictionary. The same is true with writing
dictionary to files.
in this case NSMutableDictionary is a subclass of NSDictionary, so
you're fine.
BTW... you will never get a mutable dictionary back from user defaults
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden