• 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: "Shawn Erickson" <email@hidden>
  • Date: Fri, 27 Oct 2006 13:54:16 -0700

On 10/27/06, Alan Smith <email@hidden> 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;
}

IMHO it is cleaner and functionally equivalent to have a single exit point...

- (id) init
{
   if (self = [super init]) {
       ....
       ...on init failure release ourself and set self to nil...
   }

   return self;
}

I also personally pull the self = [super init] out of the if statement
and have the if statement check against != nil. For example...

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

   return self;
}

-Shawn
_______________________________________________
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


  • Follow-Ups:
    • Re: Best practice question
      • From: j o a r <email@hidden>
References: 
 >Best practice question (From: "Alan Smith" <email@hidden>)

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