> On Apr 3, 2021, at 11:02, Gabriel Zachmann via Cocoa-dev > <cocoa-dev@lists.apple.com> wrote: > > >> >> Why not use your top level NSUserDefaults as a dictionary and use each >> monitor name as a key for each object in the dictionary? Is that too clunky? > > I was thinking of that, but I was hoping for a more elegant solution. > > With the dictionary-per-monitor your suggesting, > I guess I would have to do something like this: > > NSDictionary *monitor_dict = [NSDictionary dictionaryWithObjectsAndKeys: > displayname, defaultsForMonitor, nil ]; // where defaultsForMonitor is an > ancillary dictionary > [defaults registerDefaults: monitor_dict]; > NSDictionary * monitor_user_defaults = [defaults dictionaryForKey: > displayname]; > NSNumber * pref1num = [monitor_user_defaults valueForKey: @"Pref1"]; > real_pref1_ = [pref1num intValue]; > > I.e., I don't get the nice NSUserDefaults machinery. > > Plus, it's all or nothing, I can't have some preferences defined by the user > and some from the defaults
I’d just add extensions to NSUserDefaults so they do the messy part and you can make smoother calls: -(NSInteger) integerForKey:(NSString*)key forScreen:(NSInteger)screen { NSDictionary* dict = [self objectForKey:[NSString stringWithFormat:@“screen %ld”, screen]]; return [dict[key] integerValue]; } And of course the opposite for setting values per screen. I’d type more, but it takes forever to type code on an iPad. Steve via iPad _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com