Re: That Cocoa Book...
Re: That Cocoa Book...
- Subject: Re: That Cocoa Book...
- From: John Nestor <email@hidden>
- Date: Mon, 31 Dec 2001 14:48:37 -0500
I called my solution BoogerMan but aside from that the code was
essentially as yours.
The string allocation is done using +stringWithFormat: which produces an
autoreleased string.
Michael F Brinkman wrote:
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
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.