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