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

Good idea/bad idea?


  • Subject: Good idea/bad idea?
  • From: Alex Zavatone <email@hidden>
  • Date: Thu, 24 Apr 2014 10:33:28 -0400

I was just asked yesterday if there is any shorthand in Objective-C for "if this thing = nil, then instantiate a new instance from the class"

Something like this:

NSString x;

if ([x isEqualtoString:nil]) {
    x = @"yo";
}

Feel free to replace NSString with any class.

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";

Thanks in advance.
- Alex

_______________________________________________

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: Good idea/bad idea?
      • From: Jens Alfke <email@hidden>
    • Re: Good idea/bad idea?
      • From: Andy Lee <email@hidden>
    • Re: Good idea/bad idea?
      • From: Luther Baker <email@hidden>
    • Re: Good idea/bad idea?
      • From: Raheel Ahmad <email@hidden>
  • Prev by Date: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
  • Next by Date: Re: Good idea/bad idea?
  • Previous by thread: Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
  • Next by thread: Re: Good idea/bad idea?
  • Index(es):
    • Date
    • Thread