Newbie question regarding Learning Cocoa
Newbie question regarding Learning Cocoa
- Subject: Newbie question regarding Learning Cocoa
- From: Philippe de Rochambeau <email@hidden>
- Date: Mon, 04 Jun 2001 16:17:54 +0200
- Organization: wwphi
Hello,
I am currently working through O'Reilly's Learning Cocoa and have
problems understanding the following Obj-C code:
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?
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?
return self; why do you retain 'self'? Why do you return
it in an 'id'?
}
- (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?
}
- (void)awakeFromNib
{
[colorWell setColor: color]; how can you be sure here that
'color' points to an existing object? Did you retain it somewhere else?
[sizeSlider setFloatValue:radius];
}
@end
-(void)awakeFromNib {
...
[[NSColor whiteColor] set] why don't you retain the new
whiteColor object here, as you did above?
...
-(void)drawRect: (NSRect)rect {
...
[[NSColor whiteColor] set] what is 'set'? Was it predefined somewhere?
p. 158:
return [NSCalendarDate date] what is 'date'? Is it a function?
Any help with the above would be much appreciated.
Philippe de Rochambeau