• 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
NSUserDefaults and mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSUserDefaults and mutability


  • Subject: NSUserDefaults and mutability
  • From: Trygve Inda <email@hidden>
  • Date: Sat, 08 Mar 2008 21:57:39 +0000
  • Thread-topic: NSUserDefaults and mutability

NSUserDefaults docs say: "Values returned from NSUserDefaults are immutable"

However...

NSDictionary * dict = [[NSUserDefaults standardUserDefaults]
persistentDomainForName: @"com.mycompany.myapp"];

// dict is indeed immutable and contains one key value pair subDict which is
// another dictionary. subDict IS mutable

So after doing:

NSDictionary *    subDict = [dict objectForKey: @"mySubDict"];

[subDict setValue:someValue forKey:someKey];

[[NSUserDefaults standardUserDefaults] setPersistentDomain:dict forName:@"
com.mycompany.myapp"];
[[NSUserDefaults standardUserDefaults] synchronize];

The item mySubDict within subDict within dict in com.mycompany.myapp

IS changed.

Is this expected? Can I rely on it? I will never need to change dict, but I
am modifying items within a known sub Dictionary.

Thanks

Trygve


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSUserDefaults and mutability
      • From: Jens Alfke <email@hidden>
  • Prev by Date: No parent window for sheets?
  • Next by Date: Custom dock tile for window ...
  • Previous by thread: Re: No parent window for sheets?
  • Next by thread: Re: NSUserDefaults and mutability
  • Index(es):
    • Date
    • Thread