Perhaps just a little too OCD; however, if one is sending a message like count to a large number of containers using nil (Null) can be considerably more efficient then passing an empty shared instance. The Objective-C pattern when sending a message to a nil object pointer avoids the overhead of looking up the message implementation (even if cached) and calling that implementation. Quoting from <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ProgrammingWithObjectiveC.pdf>:
A nil value is the safest way to initialize an object pointer if you don’t have another value to use, because it’s perfectly acceptable in Objective-C to send a message to nil. If you do send a message to nil, obviously nothing happens. Note: If you expect a return value from a message sent to nil,the return value will be nil for object return types, 0 for numeric types, and NO for BOOL types. Returned structures have all members initialized to zero. —kevin > On Oct 28, 2015, at 12:59 AM,Charles Srstka <cocoa...@charlessoft.com> wrote: > >> On Oct 27, 2015, at 7:08 PM, Graham Cox <graham....@bigpond.com> wrote: >> >>> On 28 Oct 2015, at 10:53 AM, Alex Kac <a...@fanaticsoftware.com >>> <mailto:a...@fanaticsoftware.com>> wrote: >>> >>> Have you tried simply passing in a blank dictionary? Is that OK? >> >> >> Yes, that works OK. It’s at least a simple way to shut the warning up, >> though strikes me as unnecessary and inefficient, FWIW. > > It’s not that inefficient, given that an immutable empty array or dictionary > is just going to end up being a shared instance anyway, rather than actually > allocating and deallocating an object. The only costs should be asking the > container if it’s empty, and the usual ARC retain/release stuff. _______________________________________________ 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