• 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: init returns nil or raises exception?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: init returns nil or raises exception?


  • Subject: Re: init returns nil or raises exception?
  • From: Kyle Sluder <email@hidden>
  • Date: Fri, 8 Oct 2010 00:57:01 -0700

On Fri, Oct 8, 2010 at 12:04 AM, Remco Poelstra <email@hidden> wrote:
> Ah, I see. I hoped it was 'the new way to go'. I like to more than checking
> for nil, but I might be a bit lazy :)

Checking for nil and assigning to self should be reflexes. You can
combine the two if you like. Whenever I write an -init method, I
always follow the same pattern. I don't even need to think about it:

- (id)init {
  if (!(self = [super init]))
    return nil;

  // do other initialization

  return self;
}

To my brain, it might as well be required syntax.

--Kyle Sluder
_______________________________________________

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: init returns nil or raises exception?
      • From: Remco Poelstra <email@hidden>
References: 
 >init returns nil or raises exception? (From: Remco Poelstra <email@hidden>)
 >Re: init returns nil or raises exception? (From: Kyle Sluder <email@hidden>)
 >Re: init returns nil or raises exception? (From: Jean-Daniel Dupas <email@hidden>)
 >Re: init returns nil or raises exception? (From: Remco Poelstra <email@hidden>)

  • Prev by Date: Re: init returns nil or raises exception?
  • Next by Date: Re: init returns nil or raises exception?
  • Previous by thread: Re: init returns nil or raises exception?
  • Next by thread: Re: init returns nil or raises exception?
  • Index(es):
    • Date
    • Thread