• 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: returning nil on initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning nil on initialization


  • Subject: Re: returning nil on initialization
  • From: Chris Hanson <email@hidden>
  • Date: Thu, 1 Apr 2004 16:26:36 -0600

On Apr 1, 2004, at 2:21 PM, Daniel Waylonis wrote:
I'm under the impression that the result of [super init] and the
variable self will always be the same.

Not necessarily. [super init] can return a different self, particularly when class clusters are involved. This is why you should never write the following:

NSString *s = [NSString alloc];
[s init];

The first expression may return one object of one type of internal NSString subclass, while the second expression may return a different object of a different type of internal NSString subclass. If you follow the idioms properly, you won't be bitten by this.

-- Chris

PS - One other style nit: I never write return(x) because return isn't a function.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: returning nil on initialization
      • From: Andy Lee <email@hidden>
    • Re: returning nil on initialization
      • From: Bill Cheeseman <email@hidden>
References: 
 >Re: returning nil on initialization (From: Daniel Waylonis <email@hidden>)

  • Prev by Date: Which NSCompositingOperation the Dock uses for highlight the icons?
  • Next by Date: Re: returning nil on initialization
  • Previous by thread: Re: returning nil on initialization
  • Next by thread: Re: returning nil on initialization
  • Index(es):
    • Date
    • Thread