• 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
Hierarchical defaults in NSUserDefaults?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hierarchical defaults in NSUserDefaults?


  • Subject: Hierarchical defaults in NSUserDefaults?
  • From: Greg Best <email@hidden>
  • Date: Wed, 25 Jul 2007 00:21:13 -0700

I've been searching the web for an answer to this, and maybe I'm just not using the right search terms...

I'd prefer not to put all of my defaults into the root level of my preferences file-- it saves me encoding namespaces into the default's key, and hopefully will allow me to pull a dictionary from the defaults database to hand to an initializer in one chunk. I can't get it to bind properly though.

Stripping it down to a basic example, I've got my app delegate with the following code:
#import "appDel.h"


@implementation appDel

+(void)initialize
{
  NSUserDefaults* appDefaults=[NSUserDefaults standardUserDefaults];
  NSMutableDictionary* myDefaults=[NSMutableDictionary dictionary];

[myDefaults setValue:[NSMutableDictionary dictionary] forKey:@"testPath"];
[myDefaults setValue:[NSMutableDictionary dictionary] forKeyPath:@"testPath.blah"];
[myDefaults setValue:@"3.14" forKeyPath:@"testPath.blah.pi"];


[appDefaults registerDefaults:myDefaults];
//check dictionary structure
[myDefaults writeToFile:[@"~/test.plist" stringByExpandingTildeInPath] atomically:true];
}


@end

In the main window in the nib file, I have a single text box bound to Shared User Defaults, controller key is "values", and model key path is "testPath.blah.pi".

When I run, the test.plist file I create in the initialize method is what I'd expect-- it's a plist file containing a dictionary called "testPath", containing a dictionary called "blah" containing a string called "pi" equal to "3.14".

Problem is my text box comes up blank. When I enter a value, that value is retained, but my "com.yourcompany.defaultsTest.plist" preferences file contains only a string called "testPath.blah.pi" which is equal to whatever I put in that text box.

Why isn't my Model Key Path being parsed into it's component elements, and how do I convince the controller to do so?

Thanks--
 Greg

_______________________________________________

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: Hierarchical defaults in NSUserDefaults?
      • From: Greg Best <email@hidden>
  • Prev by Date: Re: Simple Undo Manager Problem
  • Next by Date: Re: C++ framework
  • Previous by thread: showing panel keeps activating other panel
  • Next by thread: Re: Hierarchical defaults in NSUserDefaults?
  • Index(es):
    • Date
    • Thread