• 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: Good idea/bad idea?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good idea/bad idea?


  • Subject: Re: Good idea/bad idea?
  • From: Alex Zavatone <email@hidden>
  • Date: Thu, 24 Apr 2014 12:56:25 -0400

On Apr 24, 2014, at 12:44 PM, Jens Alfke wrote:

>
> On Apr 24, 2014, at 7:33 AM, Alex Zavatone <email@hidden> wrote:
>
>> And we messed around a bit looking for any shorthand and though it looked like a terrible idea since the comparison is done against integers using the ternary operator, I'd like to know exactly why it's a terrible idea.
>> NSString x;
>> x = (x) ?: @"yo";
>
> It’s not a terrible idea; I use this pattern a lot.
>
> The ternary operator doesn’t just work on integers. It’s like “if”, it takes any expression that can be interpreted as a boolean. For a pointer the test is implicitly the same as “x != nil”. The example you gave is exactly equivalent to
> 	if (x)
> 		x = x;
> 	else
> 		x = @“yo”;
>
> —Jens

That's exactly what I was wondering.

I'll consider this a blessing of its legitimacy.

Awesome!
_______________________________________________

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


References: 
 >Good idea/bad idea? (From: Alex Zavatone <email@hidden>)
 >Re: Good idea/bad idea? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Good idea/bad idea?
  • Next by Date: Re: IOKit / OSX: How can I distinguish between "real hard disk" and mounted images?
  • Previous by thread: Re: Good idea/bad idea?
  • Next by thread: Re: Good idea/bad idea?
  • Index(es):
    • Date
    • Thread