- Is memory leak causing crash here, or class other implementation issue?
- #import <Foundation/Foundation.h>
- @interface Mutation : NSObject
- @property (assign) NSString *inputString;
- @property (assign) NSString *outputString;
- @end
- #import "Mutation.h"
- @implementation Mutation
- @synthesize inputString;
- @synthesize outputString;
- @end
- #import <Cocoa/Cocoa.h>
- #import "Mutation.h"
- @interface NTAppDelegate : NSObject <NSApplicationDelegate>
- @property (assign) IBOutlet NSWindow *window;
- @property (weak) IBOutlet NSTextField *dataField;
- @property (weak) IBOutlet NSTextField *outputField;
- @property (assign) Mutation *mutation;
- - (IBAction)receiveUserTextFromTextField:(NSTextField *)sender;
- @end
- #import "NTAppDelegate.h"
- #import "Mutation.h"
- @implementation NTAppDelegate
- @synthesize window = _window;
- @synthesize dataField = _dataField;
- @synthesize outputField = _outputField;
- @synthesize mutation = mutation; //statement #1
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification //#3 (block)
- {
- Mutation *aMutation = [[Mutation alloc] init];
- [self setMutation:aMutation];
- [aMutation setInputString:@"new"];
- [aMutation setOutputString:@"old"];
- NSLog(@"Mutation inputString is %@; outputString is %@", [aMutation inputString], [aMutation outputString]);
- }
- - (IBAction)receiveUserTextFromTextField:(NSTextField *)sender //#2 (block)
- {
- // assign the user's entered text to Mutation's inputString
- NSString* newText = [sender stringValue]; // -stringValue inherited from NSControl
- NSLog (@"%@ was entered", newText); // <-THIS WORKS
- [mutation setInputString:newText]; // <-CRASH statement #4 (crashes)
- NSLog(@"Mutation(2) inputString is %@; outputString is %@", [aMutation inputString], [aMutation outputString]);
- }
- @end