Axwack
Axwack

Reputation: 569

Question about instantiating object

I am new to Objective C and Cocoa. Really don't like the syntax as I'm from Java and C#. I'm trying to do something simple and I get the following error:

I import this in using

#import "Defaults.h"

-(void) awakeFromNib{
            Defaults *theDefaults = [[Defaults alloc] init];
}

-(IBAction) addPlanets:(id)sender{

[theDefaults setValue:[planetsButton titleOfSelectedItem] forKey:@"planets"];
NSLog([planetsButton titleOfSelectedItem]);
}

The error I get is

Unknown Receiver theDefaults; Did you mean "Defaults"?

Can someone help me on what this is?

Upvotes: 2

Views: 370

Answers (1)

Carl Norum
Carl Norum

Reputation: 224944

theDefaults doesn't exist in the scope of addPlanets:. You need to make it a global or an instance variable, rather than creating it in awakeFromNib and immediately leaking it.

Upvotes: 5

Related Questions