Re: Newbie question regarding Learning Cocoa
Re: Newbie question regarding Learning Cocoa
- Subject: Re: Newbie question regarding Learning Cocoa
- From: Andreas Monitzer <email@hidden>
- Date: Mon, 4 Jun 2001 17:48:55 +0200
On Monday, June 4, 2001, at 04:17 , Philippe de Rochambeau wrote:
On p. 55 :
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello world");
[pool release];
What is the purpose of creating an autorelease pool in the code above if
you are simply printing 'Hello World' onscreen?
You need a autorelease pool when using Cocoa calls (NSLog is one of them).
On page 136,
#import "DotView.h"
@implementation DotView
- (id)initWithFrame: (NSRect)frame
{
self = [super initWithFrame:frame];
center.x = 50.0;
center.y = 50.0;
radius = 10.0;
color = [[ NSColor redColor] retain]; why do you retain the new
NSColor object?
You need it in awakeFromNib. It would get released at the end of this
method (that's not really true, but you have to treat it that way).
return self; why do you retain 'self'? Why do you return
it in an 'id'?
id = any object
This class gets instantiated by doing:
aVariable=[[DotView alloc] initWithFrame:aRect];
so initWithFrame: has to return something (preferably an object of type
DotView)
}
- (void)dealloc
{
[color release];
[super dealloc]; what is DotView's parent, which you must
dealloc? Does deallocing simply mean calling DotView's parent's
dealloc method?
Yeah, it's NSObject's dealloc method
}
- (void)awakeFromNib
{
[colorWell setColor: color]; how can you be sure here that
'color' points to an existing object? Did you retain it somewhere else?
Yes, in initWithFrame:
[sizeSlider setFloatValue:radius];
}
@end
-(void)awakeFromNib {
...
[[NSColor whiteColor] set] why don't you retain the new
whiteColor object here, as you did above?
Maybe you don't need it anymore?
...
-(void)drawRect: (NSRect)rect {
...
[[NSColor whiteColor] set] what is 'set'? Was it predefined
somewhere?
set is a method. Look at the reference for more details.
p. 158:
return [NSCalendarDate date] what is 'date'? Is it a function?
Same as above.
andy
--
Description forthcoming.