The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Alex Zavatone
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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Mike Abdullah
> On 10 Nov 2015, at 16:32, Alex Zavatone 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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Jens Alfke
> On Nov 10, 2015, at 8:32 AM, Alex Zavatone wrote: > > 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". I don’t know any reason why it would be bad, although I don’t typically use it.

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Quincey Morris
On Nov 10, 2015, at 10:52 , Alex Zavatone 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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Greg Weston
> 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"™, I would like to see these

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread David Duncan
> On Nov 10, 2015, at 8:32 AM, Alex Zavatone 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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Jens Alfke
> On Nov 10, 2015, at 10:52 AM, Alex Zavatone 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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Alex Zavatone
And you guys have no idea how useful this discussion was to me today. Even though the KVO valueForKey: method doesn't crater with an NSUnknownException with ease, it turns out that this wonderful code is also using the KVO method of setValue: forKey: on a dictionary. And guess what? ***

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Gary L. Wade
Lots of stuff with that. An immutable dictionary can't be changed. Someone doesn't know how to spell unknown (NSUnknosnKeyException). And not sure if that period is part of the key username or just good English, but if given as part of the key, it becomes a key path with an empty key. Anyway,

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Alex Zavatone
On Nov 10, 2015, at 2:15 PM, Jens Alfke wrote: > >> On Nov 10, 2015, at 10:52 AM, Alex Zavatone wrote: >> >> Here's a great reason to use objectForKey: wherever possible instead of >> valueForKey: - valueForKey: with an unknown key will throw >> NSUnknownKeyException saying

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Jean-Daniel Dupas
> Le 10 nov. 2015 à 19:52, Alex Zavatone a écrit : > > > On Nov 10, 2015, at 12:35 PM, Greg Weston 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 >>>

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread Greg Weston
> On Nov 10, 2015, at 15:21, Alex Zavatone wrote: > > >> Yeah. Honestly, I'm looking for cases that would justify why all the >> dictionary object access blocks in this code that use valueForKey are >> wrapped with @try/@catch clauses. I've never seen cases with objectForKey