> On Nov 10, 2015, at 10:52 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> Here's a great reason to use objectForKey: wherever possible instead of 
> valueForKey: - valueForKey: with an unknown key will throw 
> NSUnknownKeyException saying "this class is not key value coding-compliant 
> for the key ".

Yes, but that’s a non-issue with NSDictionary because there are no unknown 
keys. It handle any key (that doesn’t start with an @) by looking it up in the 
dictionary.

I’m not saying you should use -valueForKey, just that you need to be clear on 
its behavior on _arbitrary_ objects vs. its behavior with NSDictionary.

> But if we remove the @ (obviously unintended), valueForKey causes an 
> EXC_BAD_ACCES while objectForKey reports "error: string literal must be 
> prefixed by '@'".

Um … you’re doing that in lldb? The difference there seems like an lldb bug. It 
shouldn’t be allowing you to pass a C string literal as an id, no matter what 
method is being called.

> And David does state that whether an exception is thrown or not is 
> implementation dependent.  

Yes, the implementation OF THE CLASS BEING CALLED. Which is NSDictionary. 
Which, as we keep saying, handles any key by looking it up in the dictionary.

—Jens
_______________________________________________

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