Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.74 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is memory leak causing crash here, or class other implementation issue?
  2. #import <Foundation/Foundation.h>
  3. @interface Mutation : NSObject
  4. @property (assign) NSString *inputString;
  5. @property (assign) NSString *outputString;    
  6. @end
  7.        
  8. #import "Mutation.h"
  9. @implementation Mutation
  10. @synthesize inputString;
  11. @synthesize outputString;
  12. @end
  13.        
  14. #import <Cocoa/Cocoa.h>
  15. #import "Mutation.h"
  16. @interface NTAppDelegate : NSObject <NSApplicationDelegate>
  17. @property (assign) IBOutlet NSWindow *window;
  18. @property (weak) IBOutlet NSTextField *dataField;
  19. @property (weak) IBOutlet NSTextField *outputField;
  20. @property (assign) Mutation *mutation;
  21. - (IBAction)receiveUserTextFromTextField:(NSTextField *)sender;
  22. @end
  23.        
  24. #import "NTAppDelegate.h"
  25. #import "Mutation.h"
  26. @implementation NTAppDelegate
  27. @synthesize window = _window;
  28. @synthesize dataField = _dataField;
  29. @synthesize outputField = _outputField;
  30. @synthesize mutation = mutation;    //statement #1
  31.  
  32. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification //#3 (block)
  33. {
  34. Mutation *aMutation = [[Mutation alloc] init];
  35. [self setMutation:aMutation];
  36. [aMutation setInputString:@"new"];
  37. [aMutation setOutputString:@"old"];
  38. NSLog(@"Mutation inputString is %@; outputString is %@", [aMutation inputString], [aMutation outputString]);    
  39. }
  40.  
  41. - (IBAction)receiveUserTextFromTextField:(NSTextField *)sender   //#2 (block)
  42. {
  43. // assign the user's entered text to Mutation's inputString
  44. NSString* newText = [sender stringValue];   // -stringValue inherited from NSControl
  45. NSLog (@"%@ was entered", newText);         //  <-THIS WORKS
  46. [mutation setInputString:newText];           //  <-CRASH  statement #4 (crashes)
  47. NSLog(@"Mutation(2) inputString is %@; outputString is %@", [aMutation inputString], [aMutation outputString]);    
  48. }
  49.  
  50. @end