PDA

View Full Version : dealloc method error??? Kochan page 180




mdeh
Jan 13, 2009, 06:36 PM
On p 180 of 2.0, the dealloc method is defined thus.


-(id) dealloc
{
if (origin)
[origin release];
return [super dealloc];
}

Should it not be this?


-(void) dealloc
{
if (origin)
[origin release];
[super dealloc];
}


I think there might also be a misquote on the same page.

"The dealloc method is defined to return a value of type id. You know this by looking inside the header file <NSObject.h>.....

NSObject.h shows this though....
- (void)dealloc;

Thanks in advance.



kainjow
Jan 13, 2009, 06:40 PM
Yes, dealloc doesn't have a return type.

skochan
Jan 14, 2009, 03:06 PM
I think there might also be a misquote on the same page.

"The dealloc method is defined to return a value of type id. You know this by looking inside the header file <NSObject.h>.....

NSObject.h shows this though....
- (void)dealloc;

Thanks for the catch! Later in the book dealloc is correctly referenced as a void method.

[The first edition used Object as the root object at this point in the text (and Object.h as the root header file). In that case, the free method, which does return an id object, was the method that was overridden. This didn't do well in the translation to NSObject!]



Cheers,

Steve Kochan