Re: The joys of people using valueForKey to get objects out of a dictionary.
Re: The joys of people using valueForKey to get objects out of a dictionary.
- Subject: Re: The joys of people using valueForKey to get objects out of a dictionary.
- From: Quincey Morris <email@hidden>
- Date: Tue, 10 Nov 2015 11:17:49 -0800
- Feedback-id: 167118m:167118agrif8a:167118scaxW3b3RI:SMTPCORP
- X_v_e_cd: 2efdcc769f0c81c102842cc721ed7662
- X_v_r_cd: 51be3115673a2b668091864abaf29c01
On Nov 10, 2015, at 10:52 , Alex Zavatone <email@hidden> wrote:
>
> For what we're doing on a daily basis, if we're not using @ within our keys, I still can't see anything concrete besides "objectForKey is an NSDictionary method" while "valueForKey is a KVO method".
You don’t really have to agonize over this. ‘objectForKey’ is the correct method to use. That is to say, if your code is working with a variable of type NSDictionary or NSMutableDictionary, the NSDictionary API is the correct one to use. There’s absolutely no need to take a detour via KVC.
Similarly, you should remove the try/catch blocks, if they do nothing but trap the case where there is no object for the given key. In that situation, the nil return is mandatory for the implementation. Any other exceptions should be uncaught, and allowed to crash the app, according to current best practices.
Note that there may be an interesting-to-some discussion over whether and how NSDictionary’s interpretation of KVC's ‘valueForKey’ happens to overlap in functionality with NSDictionary’s ‘objectForKey’. Continue that discussion if you like, but use ‘objectForKey’ anyway.
_______________________________________________
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