• 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
Re: initializer methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >initializer methods (From: Lynn Barton <email@hidden>)

  • Prev by Date: Re: initializer methods
  • Next by Date: Re: How to avoid text distortion
  • Previous by thread: Re: initializer methods
  • Next by thread: How to avoid the movie distortion ?
  • Index(es):
    • Date
    • Thread