Re: using NSMutableDictionary in place of NSDictionary
Re: using NSMutableDictionary in place of NSDictionary
- Subject: Re: using NSMutableDictionary in place of NSDictionary
- From: Óscar Morales Vivó <email@hidden>
- Date: Fri, 24 Feb 2006 16:02:05 -0500
I'd put my hand in the fire and say that when the documentation talks
about "using a NSDictionary" it does mean "using NSDictionary or any
derived class" as per object oriented principles.
Of course, if your program is multithreaded you won't want to modify
your NSMutableDictionary while it's being written to file, but other
than that you ought to be safe on a matter of principle. And if you
ran into trouble, it wouldn't be your fault ;)
On Feb 24, 2006, at 14:36 , Steve Sheets wrote:
You can safely say that we have recently discovered the joys of
NSDictionary, and have seen the light. We are starting to use use
them to handle static application data, user defaults and document
data. We have noticed one consistent coding strategy, and want to
hear some comments on this.
Almost always, when working with persistent, non-static
dictionaries (ie. ones that the program changes), we convert the
NSDictionary into an NSMutableDictionary. Sometimes the dictionary
contains sub-dictionaries, and we walk the tree, converting them as
we go.
When we want to save this information, do we have to convert this
mutable dictionary back to the NSDictionary, or can we save save it
as NSMutableDictionary? The two main sets of read/write calls we
are referring to:
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
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.
This question turned out to be more long winded that it needed to
be, so simple answers would be fine with us!
As always, thanks!
Steve Sheets
Midnight Mage Software
_______________________________________________
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
_______________________________________________
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