On 25/11/2009, at 12:17 PM, Ben Haller wrote:

> - There's a little bit of duplication of information between the nib and the 
> code.  The tags on the radio button matrix's cells have to match the values 
> in the enumeration, for one thing.  Even more annoyingly, the strings for the 
> defaults keys have to correspond to the bindings key paths I enter in IB.  
> This duplication seems like a vulnerability (not that it wouldn't also be 
> there without using bindings, of course).  There isn't any reasonable way to 
> get rid of this, is there?

Unfortunately not. Key paths are just strings and you can't use symbolic 
constants in Interface Builder, you have to use the string itself. Yes, it's 
fragile.

> - A little bit of glue code still seems to be necessary (or at least 
> aesthetic) to vend the user defaults to client code (i.e. the +launchAction, 
> +sgeHeadNode, etc. class methods).  I could get rid of them, but then I'd 
> have to export the defaults keys in the header, and every client of the 
> preferences would have to do the same thing as this glue code themselves, so 
> the current way seems preferable (no pun intended :->).  Am I missing a way 
> to make this code nicer, or will I have to add a glue method like this every 
> time I add a defaults key?


When you retrieve and initialize the values you can just use regular user 
defaults, you don't have to use the NSUserDefaultsController. The user defaults 
controller that you use in bindings just pipes the values directly into 
NSUserDefaults so unless you need the additional functionality of the user 
defaults controller  in your code you can ignore it.

+ (void)initialize
{
        NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
                                                                
@"my.server.com", akSGEHeadNodeKey,
                                                                @"username", 
akSGEUsernameKey,
                                                                @"password", 
akSGEPasswordKey,
                                                                [NSNumber 
numberWithInt:akLaunchShowNewSimulationPanel], akLaunchActionKey,
                                                                nil];
        [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}

+ (AKLaunchAction)launchAction
{
        return (AKLaunchAction)[[[NSUserDefaults standardUserDefaults] 
objectForKey:akLaunchActionKey] intValue];
}

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to