• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
initializer methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: initializer methods
      • From: "Sean McBride" <email@hidden>
    • Re: initializer methods
      • From: Roland King <email@hidden>
  • Prev by Date: Re: Stretching NSImage PNGs smoothly
  • Next by Date: Re: Stretching NSImage PNGs smoothly
  • Previous by thread: Re: Stretching NSImage PNGs smoothly
  • Next by thread: Re: initializer methods
  • Index(es):
    • Date
    • Thread