• 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 19:21:07 -0400

On Apr 24, 2014, at 5:21 PM, Andy Lee wrote:

>
> On Apr 24, 2014, at 4:10 PM, Alex Zavatone <email@hidden> wrote:
>
>> Could we throw a category on NSObject for that and then every class that originates with NSObject gets that lovely method?
>
> Not exactly, because unlike Smalltalk's nil, Objective-C's nil is *not* an object.  But you could switch it around:
>
> @implementation NSObject (NilCheck)
> - (id)fallbackIfNil:(id)obj { return obj ?: self; }
> @end
>
> I still don't see how
>
> foo = [@"Something" fallbackIfNil:foo];
>
> has any advantage over
>
> foo = foo ?: @"Something";
>
> which is less verbose, doesn't have the cost of a message send, and uses an operator the reader of the code should already know.
>
> --Andy

Yeah, I was thinking about something less verbose, but still expressive of the task trying to be accomplished.

something like…

z = [initMeIfNil: z as:@"my most awesome string ever"];

Or something to that effect but neater and tinier.

- 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


References: 
 >Good idea/bad idea? (From: Alex Zavatone <email@hidden>)
 >Re: Good idea/bad idea? (From: Luther Baker <email@hidden>)
 >Re: Good idea/bad idea? (From: Lee Ann Rucker <email@hidden>)
 >Re: Good idea/bad idea? (From: Alex Zavatone <email@hidden>)
 >Re: Good idea/bad idea? (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: ARC Retain Cycles
  • Next by Date: Re: ARC Retain Cycles
  • Previous by thread: Re: Good idea/bad idea?
  • Next by thread: Re: Good idea/bad idea?
  • Index(es):
    • Date
    • Thread