NSUserDefaultsController in a NIB when not using standardUserDefaults
NSUserDefaultsController in a NIB when not using standardUserDefaults
- Subject: NSUserDefaultsController in a NIB when not using standardUserDefaults
- From: Alex Kac <email@hidden>
- Date: Mon, 08 Sep 2014 12:09:53 -0600
This feels like there should be an easy answer...
We are no longer using standardUserDefaults since we want to someday offer a widget for our app that will require accessing our app's preferences..so we're using NSUserDefaults with a custom suiteName.
*The question is*: in the NIBs for our Preference panes, we had various UI elements bound to NSUserDefaultsController. The normal NSUserDefaultsController in IB is set to only use standardUserDefaults. Is there any way to have it use our userdefaults instead?
I did come up with one way - but I don't I love it. I made a subclass of NSUserDefaultsController and in the initWithCoder method, I tell it to use our defaults...of course, I have to first call super or else I'll get a compiler warning (which feels like a waste and causes me to re-assign self)...so here's what I have now:
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder: coder];
self = (MyUserDefaultsController *)[[NSUserDefaultsController alloc] initWithDefaults: myUserDefaults initialValues:nil];
return self;
}
Is there a better way?
_______________________________________________
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