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

using NSMutableDictionary in place of NSDictionary


  • Subject: using NSMutableDictionary in place of NSDictionary
  • From: Steve Sheets <email@hidden>
  • Date: Fri, 24 Feb 2006 14:36:17 -0500

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


  • Follow-Ups:
    • Re: using NSMutableDictionary in place of NSDictionary
      • From: Scott Anguish <email@hidden>
    • Re: using NSMutableDictionary in place of NSDictionary
      • From: James Dempsey <email@hidden>
    • Re: using NSMutableDictionary in place of NSDictionary
      • From: Greg Herlihy <email@hidden>
    • Re: using NSMutableDictionary in place of NSDictionary
      • From: Óscar Morales Vivó <email@hidden>
  • Prev by Date: Re: String causes NSLog to crash
  • Next by Date: Re: AddressBook Problem
  • Previous by thread: Re: String causes NSLog to crash
  • Next by thread: Re: using NSMutableDictionary in place of NSDictionary
  • Index(es):
    • Date
    • Thread