initializer methods
initializer methods
- Subject: initializer methods
- From: Lynn Barton <email@hidden>
- Date: Thu, 19 Nov 2009 20:15:35 -0800
After many years of using procedural programming languages, I am trying to learn Cocoa. Today I am reading the Apple document "The Objective-C Programming Language" dated 2009-10-19. On page 46 I read the following:
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?
Lynn_______________________________________________
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