> On Nov 10, 2015, at 8:32 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> It's been about 4 or 5 years since I made this mistake but I've just seen a 
> massive swath of code where every access of a dictionary object is using 
> valueForKey instead of objectForKey.
> 
> I've got a few examples of why this is a "really bad idea"™, and certainly 
> might explain why lots of that code is wrapped in try/catch blocks.
> 
> Am I correct that using valueForKey will raise an exception if the key is 
> missing?
> 
> Looking for reasons why I can explain "yeah, I know it works, but here's why 
> it's a terrible idea to use to access a dictionary's objects".
> 
> Thanks in advance.


I will note that the exception throwing behavior is implementation dependent - 
NSDictionary may not throw but I’ve had experience with other objects that do, 
and this may be the generic behavior on NSObject (I haven’t checked).
--
David Duncan


_______________________________________________

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

Reply via email to