Newbie Q - Variables not being retained in class
Newbie Q - Variables not being retained in class
- Subject: Newbie Q - Variables not being retained in class
- From: Aaron Wallis <email@hidden>
- Date: Sat, 10 Sep 2005 01:57:03 +1000
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