Okay, I'm steadily working through Aaron Hilleglasses brilliant book on Cocoa and have just completed the character count program and it works.
Thing is though, I'm quite keen not to rely on garbage collection and am not sure if I've really understood retaining and releasing properly.
Initially, I thought I should ask it to release typedText and result and the program worked the first time and then hung. Am I right in thinking that NSString objects are dealt with by the NSAutoRelease pool? Other thing I'm not quite sure about is how retain counts relate to IBActions and IBOutlets.
Would be grateful to hear people thoughts and hopefully clear up my own in the process.
Thing is though, I'm quite keen not to rely on garbage collection and am not sure if I've really understood retaining and releasing properly.
Initially, I thought I should ask it to release typedText and result and the program worked the first time and then hung. Am I right in thinking that NSString objects are dealt with by the NSAutoRelease pool? Other thing I'm not quite sure about is how retain counts relate to IBActions and IBOutlets.
Would be grateful to hear people thoughts and hopefully clear up my own in the process.
Code:
#import "CountController.h"
@implementation CountController
- (IBAction)count:(id)sender
{
NSString *typedText = [textField stringValue];
NSString *result = [[NSString alloc]initWithFormat:@"The number of characters in your sentence is %d",[typedText length]];
[countResult setStringValue:result];
}
@end