• 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: using NSMutableDictionary in place of NSDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >using NSMutableDictionary in place of NSDictionary (From: Steve Sheets <email@hidden>)

  • Prev by Date: Re: draw and ... draw, not drawing
  • Next by Date: Re: Mutable/non-mutable bindings in NSTextView
  • Previous by thread: Re: using NSMutableDictionary in place of NSDictionary
  • Next by thread: add applied to 2 related models simultaneously
  • Index(es):
    • Date
    • Thread