• 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: -(id)init methods, NSExceptions, and returning nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -(id)init methods, NSExceptions, and returning nil


  • Subject: Re: -(id)init methods, NSExceptions, and returning nil
  • From: Kyle Sluder <email@hidden>
  • Date: Mon, 27 Jun 2011 09:30:52 -0700

On Mon, Jun 27, 2011 at 6:38 AM, Roland King <email@hidden> wrote:
>> The favored form for writing an init method seems to be
>>
>> -(id)init
>> {
>> if (self = [super init])
>>  {
>>  // Do something here
>>  }
>> return self;
>> }
>
> actually I think the current favoured method is
>
> -(id)init
> {
>        self = [ super init ];
>
>        if( self )
>        {
>                // your code here
>        }
>
>        return self;
> };

These are equivalent. All you did was move the self assignment out of
the if statement.

I actually prefer to use `if (!(self = [super init])) return nil;`.
Again, it is equivalent.

--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: -(id)init methods, NSExceptions, and returning nil
      • From: Roland King <email@hidden>
References: 
 >-(id)init methods, NSExceptions, and returning nil (From: William Squires <email@hidden>)
 >Re: -(id)init methods, NSExceptions, and returning nil (From: Roland King <email@hidden>)

  • Prev by Date: Re: -(id)init methods, NSExceptions, and returning nil
  • Next by Date: Re: -(id)init methods, NSExceptions, and returning nil
  • Previous by thread: Re: -(id)init methods, NSExceptions, and returning nil
  • Next by thread: Re: -(id)init methods, NSExceptions, and returning nil
  • Index(es):
    • Date
    • Thread