• 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: Best practice question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practice question


  • Subject: Re: Best practice question
  • From: Glen Simmons <email@hidden>
  • Date: Fri, 27 Oct 2006 15:54:12 -0500


On Oct 27, 2006, at 3:46 PM, Alan Smith wrote:

Hi all,

I've seen many variations of the init method and I'm wondering which
is the best way to go. Currently I do it like this;

- (id)init
{
 if (self = [super init])
 {
   // Perform init code
   return self;
 }
 return nil;
}

Many thanks, Alan


I don't care for multiple return statements, and in your code, the second one is redundant anyway, so I'd do it like this:

- (id)init
{
self = [super init]; // Putting this here avoids a warning about unintentional assignment in the if below
if (self)
{
// Do stuff
}
return self; // Only need one return b/c we're testing for nil in the if above
}


(typed in Mail, blah blah)

HTH,
Glen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Best practice question (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: Seeking debugging advice
  • Next by Date: Re: Best practice question
  • Previous by thread: Best practice question
  • Next by thread: Re: Best practice question
  • Index(es):
    • Date
    • Thread