yes I know it's equivalent, didn't say it wasn't, I said it was the favored 
form, which I remembered from Scott's message a year ago in this thread 

        
http://www.cocoabuilder.com/archive/cocoa/286849-self-super-init-nil.html#286952

where he said 

        This has been, or is being updated.

        The suggested pattern is now

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

                }
                return self;
        }

        All our documentation has been updated to reflect this (even if it 
hasn’t necessarily made it out to the users yet)

ok he said 'suggested', I didn't look up the message until now. I believe 
that's the version all the templates give you and my fingers have eventually 
started doing it this way too. 

Nobody ever did answer the question why Apple prefers that form though, or if 
they did, I sure don't remember the answer. 


On 28-Jun-2011, at 12:30 AM, Kyle Sluder wrote:

> On Mon, Jun 27, 2011 at 6:38 AM, Roland King <[email protected]> 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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to