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: Alexander von Below <email@hidden>
- Date: Fri, 9 Sep 2005 18:33:10 +0200
I am not sure if one should retain the prefs, I just get them again
in every method.
But "normal" variables should be retained, otherwise they will be
purged. Suggested reading: http://developer.apple.com/documentation/
Cocoa/Conceptual/CocoaObjects/Articles/CocoaLifeCycle.html
Alex
On 09.09.2005, at 17:57, Aaron Wallis wrote:
Hi there fellow Cocoa'ers,
im still kinda new to Cocoa [and c style programming to be honest].
And I seem to be having issues with variables not being available
throughout the class...
As a simple example, here is some code:
[ myClass.h ]
@interface mpPreferences : NSObject
{
NSMutableArray * myTagFields;
NSUserDefaults * myPrefs;
}
- ( void ) setupPreferences;
- ( void ) savePreferences;
[ myClass.m ]
#import "mpPreferences.h"
@implementation mpPreferences
- ( void ) setupPreferences
{
NSMutableDictionary * defaultPrefs = [NSMutableDictionary
dictionary];
[defaultPrefs setObject:@"%" forKey:@"ExpressionKey"];
[defaultPrefs setObject:@"(" forKey: @"ExpressionIn"];
[defaultPrefs setObject:@")" forKey:@"ExpressionOut"];
myPrefs = [NSUserDefaults standardUserDefaults];
[myPrefs registerDefaults : defaultPrefs];
}
- ( void ) savePreferences
{
[ myTextKey setStringValue: [myPrefs
objectForKey:@"ExpressionKey"] ];
[ myTextIn setStringValue: [myPrefs
objectForKey:@"ExpressionIn" ] ];
[ myTextOut setStringValue: [myPrefs
objectForKey:@"ExpressionOut"] ];
}
Now, when I call setupPreferences the defaults are created [I can
see the pref file in my library], however, when I call
savePreferences, myPrefs is equal to nil...
Now, as I said, im new to cocoa, but I take it this has to do with
memory management?.... maybe? or do I have a syntax error? maybe???
Any pointers would be grealty appreciated.
Ta !!
_Az.
_______________________________________________
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
_______________________________________________
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