• 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: Looking at self = [super init].
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking at self = [super init].


  • Subject: Re: Looking at self = [super init].
  • From: Alex Zavatone <email@hidden>
  • Date: Fri, 29 May 2015 14:02:03 -0400

On May 29, 2015, at 1:42 PM, Quincey Morris wrote:

> On May 29, 2015, at 10:35 , Jean-Daniel Dupas <email@hidden> wrote:
>>
>> You must at least returns nil in the fast path, else the compiler will not be happy.
>
> Shame on you, Jean-Daniel, for not spotting the other error!
>
> On May 29, 2015, at 10:22 , Alex Zavatone <email@hidden> wrote:
>>
>>    if (self != [super init]) {
>>        return;
>>    }
>
> The opposite of ‘if (self = [super init])’ isn’t ‘if (self != [super init])’. The correct code is:
>
> 	self = [super init];
> 	if (self == nil)
> 		return nil;
>
>> I'm not smoking crack here, am I?
>
> We only have your word for it.
>
>> Does this actually seem like a good idea?
>
>
> Of course it’s a good idea (minus the two glaring bugs).


Heh, yeah, it's been a LOOOONG week.  I certainly can't see through the glare too well.

Regarding Daniel's next email, yeah, I kind of really dislike the extra indent for the entire init function.  It just seems so wrong.

Glad I asked.  I'm certainly not the first person to come across this.  Daniel's friend's solution seems good.  However, the !self comment shows the same error Simon points out below.

Also, Simon points out another error in my assumption.

> what if [super init] returned something different than self, yet not nil?
>
> In that case, your code wouldn’t be correct, as a general rule...

Hmmm.  This little comparison does flip the BOOL.

if (!(self == [super init]))

Anyway, thanks for the Friday feedback and observations.

Cheers,
Alex Zavatone
_______________________________________________

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: Looking at self = [super init].
      • From: Jens Alfke <email@hidden>
References: 
 >Looking at self = [super init]. (From: Alex Zavatone <email@hidden>)
 >Re: Looking at self = [super init]. (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Looking at self = [super init]. (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSDocumentTitlebarPopoverViewController zombie on Yosemite
  • Next by Date: Re: Looking at self = [super init].
  • Previous by thread: Re: Looking at self = [super init].
  • Next by thread: Re: Looking at self = [super init].
  • Index(es):
    • Date
    • Thread