• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Newbie Q - Variables not being retained in class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Newbie Q - Variables not being retained in class
      • From: Charlton Wilbur <email@hidden>
    • Re: Newbie Q - Variables not being retained in class
      • From: Nick Zitzmann <email@hidden>
    • Re: Newbie Q - Variables not being retained in class
      • From: Daniel Jalkut <email@hidden>
    • Re: Newbie Q - Variables not being retained in class
      • From: Alexander von Below <email@hidden>
  • Prev by Date: NSBitmapImageRep and 32bit floating-point samples
  • Next by Date: Re: Newbie Q - Variables not being retained in class
  • Previous by thread: NSBitmapImageRep and 32bit floating-point samples
  • Next by thread: Re: Newbie Q - Variables not being retained in class
  • Index(es):
    • Date
    • Thread