Re: Newbie Q - Variables not being retained in class
Re: Newbie Q - Variables not being retained in class
- Subject: Re: Newbie Q - Variables not being retained in class
- From: Jack <email@hidden>
- Date: Sat, 10 Sep 2005 11:28:31 -0400
> anyway, now that I understand what the hell is going on, does anyone
> have any pointers on how to fix this?
Aaron, as other pointed out, removing "NSUserDefaults * myPrefs;" as an
instance variable to the class and making it local will fix the problem. As
[NSUserDefaults standardUserDefaults] is the same even if you call it in a
separate instance and the registered domain is available globally.
- ( void ) savePreferences
{
NSUserDefaults myPrefs = [NSUserDefaults standardUserDefaults];
[ myTextKey setStringValue: [myPrefs
objectForKey:@"ExpressionKey"] ];
[ myTextIn setStringValue: [myPrefs
objectForKey:@"ExpressionIn" ] ];
[ myTextOut setStringValue: [myPrefs
objectForKey:@"ExpressionOut"] ];
}
Doing this will ensure that myPrefs is initialized always. And you won't
get nil. This is a solution, however to use only one instance instead of
two, pass in mypreference as the file owner when you load your
preference.nib with:
mpPreference *mypreference = [[ mpPreference alloc ] initPreferences ]; //
this is what you initialized in the core of your app. When loading your nib
do:
if ( myTextKey == nil) {
if (![NSBundle loadNibNamed:@"preference.nib" owner:
mypreference] ) {
MyLog(@"Load of preference.nib Failed");
return;
}
}
It sounds like your loading your nib at startup, and not dynamically, so
look information up about dynamic loading nibs in the archives or at
cocoadev.com as this is the efficient way to handle separate nibs.
Jack
www.bruji.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden