#import "Mutation.h" //my class
@implementation NTAppDelegate
using app delegate as controller
@synthesize window = _window;
@synthesize dataField = _dataField;
@synthesize OutputField = _OutputField;
@synthesize mutation;
why not _mutation?
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Mutation *aMutation = [[Mutation alloc] init];
[self setMutation:aMutation];
[self.mutation setInputString:@"new"];
[self.mutation setOutputString:@"old"];
NSLog(@"Mutation inputString is %@; outputString is %@",[mutation inputString],[mutation outputString]);
}
getUserText is supposed to take a text field entry string and stick it into an ivar in my mutation object…
- (IBAction)getUserText:(NSTextField *)sender
{
// assign the users entered text to mutation's inputString
NSString* newText = [sender stringValue];
-stringValue inh from NSControl EUREKA!
NSLog (@"%@ was entered", newText);
THE ABOVE WORKS
[mutation setInputString:newText];
THE ABOVE CRASHES, bad sell? can not call mutation.
}
I can tell you the _mutation is purely a matter of preference. Instead of the property creating an instance variable named mutation it creates one named _mutation. This is helpful when you want to distinguish instance variables from locally generated variables (you don’t have to write self.mutation, because it is an instance variable it is inferred)
In objective c when you @synthesize things you can name the instance variable anything. So you could write:
@synthesize mutation = thisIsMyMutation;
As to why your code is crashing, I think it is because you retain the property when you declare it so that it is strongly typed. Don’t remove the retain from the declaration, because the object should be retained. Instead, rewrite your code so that you allocate memory for the property before you use it.
SUMMARY: I believe your problem lies in the fact that you don’t allocate memory for the property. This is normally done in the init function. Because your in the app delegate if you do it in the didFinishLaunching it should work just fine.