On Apr 24, 2014, at 11:14 AM, Alex Zavatone <z...@mac.com> wrote: > > 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.
It's even lazier :) *and* more efficient (in the CPU sense) to use the binary ?:, aka the "otherwise" operator: <https://jeremywsherman.com/blog/2013/01/21/the-otherwise-operator/> On a side note, although ":" is legal as a component of a method name -- you could have a method called ":::::" if you wanted -- I would strongly recommend against using it. The purpose of Objective-C's distinctive method syntax is so that you can describe each argument with a bit of wording that is right next to the argument. Apple has a few API methods with naked colons, e.g. functionWithControlPoints::::. IMO that was a mistake. --Andy _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com