That Cocoa Book...
That Cocoa Book...
- Subject: That Cocoa Book...
- From: "Michael F Brinkman" <email@hidden>
- Date: Mon, 31 Dec 2001 13:23:03 -0500 (EST)
I just bought the "Cocoa Programming for Mac OS X", and went to the web page to
look for a solution to the challenge problem on page 102. There isn't a
solution to the challenge question posted.
I made an application called "LetterCounter", which works, but I wanted to
compare my solution to the book's. I'm not really sure what I was supposed to
do with allocating and deallocating memory, or if I'm even supposed to do
something.
This is what I put in my Controller.h file:
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
{
IBOutlet id inputField;
IBOutlet id outputField;
NSString *myString;
int myCount;
}
- (IBAction)countButton:(id)sender;
@end
This is what I put in my Controller.m file:
#import "Controller.h"
@implementation Controller
- (void)awakeFromNib
{
[outputField setStringValue: @"???"];
}
- (IBAction)countButton:(id)sender
{
myString = [inputField stringValue];
myCount = [myString length];
[outputField setStringValue: [NSString stringWithFormat: @"%@ contains %d
letters", myString, myCount]];
}
@end
Is there something I'm supposed to do in order to handle memory allocation and
destroying myString?
Over all, I've enjoyed the book (I got it yesterday and have gone through the
first 100 pages), but I wish the web site had solutions to the challenge
questions. You think it would, since I just dropped $45 on it and it didn't
come with a CD. Am I being unreasonable, or have I simply overlooked something?
Anyway, sorry for the mini-rant, any help on a solution to the programming
problem or the web page problem would be greatly appreciated!
Happy New Year!
Mike Brinkman