Re: Newbie question regarding Learning Cocoa
Re: Newbie question regarding Learning Cocoa
- Subject: Re: Newbie question regarding Learning Cocoa
- From: rsharp <email@hidden>
- Date: Mon, 4 Jun 2001 10:26:51 -0500 (CDT)
As a new person to Cocoa myself, I'll try to answer these the best I can:
On Mon, 4 Jun 2001, 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?
The book explains that the autorelease pool will be covered in a later
chapter.
>
@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'?
>
}
If you're familiar with C++, think of "self" as "this". You are
currently initializing yourself. Perhaps re-read the section on "init
chaining".
>
- (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?
>
}
Yes, super evaluates the your objects parent.
>
-(void)drawRect: (NSRect)rect {
>
...
>
[[NSColor whiteColor] set] what is 'set'? Was it predefined somewhere?
set is a message the will be sent to the return value of [NSColor
whiteColor]
>
return [NSCalendarDate date] what is 'date'? Is it a function?
date is a message (function/method) that will be send to the
NSCalendarDate object. I believe that this is actually a class method
since you are using the class name rather than an instance identifier.
HTH,
Rick Sharp
Instant Interactive