Re: Good idea/bad idea?
Re: Good idea/bad idea?
- Subject: Re: Good idea/bad idea?
- From: Alex Zavatone <email@hidden>
- Date: Thu, 24 Apr 2014 11:14:35 -0400
On Apr 24, 2014, at 11:12 AM, Luther Baker wrote:
> Not native and I've no idea when or if this is a good idea ... nor am I sure how much typing you want to do ... but you _could_ create a class convenience method for this
>
> x = [Thing defaultIfNil:x];
>
> With shorter or longer names as you see fit ... down to possibly:
>
> x = [Thing :x]
>
> I've really no idea if that syntax would work but it stands out and might be easy to use and identify in the code!
>
> -Luther
Heey, that's awesome.
The efficiency monger (aka lazy programmer) who posed me the question in the first place will like that.
>
>> On Apr 24, 2014, at 9:33 AM, Alex Zavatone <email@hidden> wrote:
>>
>> 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
_______________________________________________
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