Re: initializer methods
Re: initializer methods
- Subject: Re: initializer methods
- From: "Sean McBride" <email@hidden>
- Date: Thu, 19 Nov 2009 23:40:37 -0500
Lynn Barton (email@hidden) on 2009-11-19 11:15 PM said:
>This is an example of what not to do:
>+ (Rectangle *)rectangleOfColor:(NSColor *) color
>{
> self = [[Rectangle alloc] init]; // BAD
> [self setColor:color];
> return [self autorelease];
>}
>
>However, on page 49 I read the following:
>
>There are several constraints and conventions that apply to initializer
>methods that do not apply to other methods:
>.
>.
>.
>• You should assign self to the value returned by the initializer.
>This is because the initializer could return a different object than the
>original receiver.
>
>Could someone please explain this apparent contradiction?
There's no contradiction because +rectangleOfColor: is not an
initializer method. Initializers 1) start with init and 2) are instance
methods, not class methods (start with a - not a +). Page 49 is talking
about implementing custom initializers, rectangleOfColour is not one.
Good luck!
Sean
--
"Freedom is never voluntarily given by the oppressor; it must be
demanded by the oppressed." - Martin Luther King
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden