Re: Problem using dictionary
Re: Problem using dictionary
- Subject: Re: Problem using dictionary
- From: Quincey Morris <email@hidden>
- Date: Mon, 18 Oct 2010 21:33:09 -0700
On Oct 18, 2010, at 20:52, Abhi Beckert wrote:
> [NSObject valueForKey:] has nothing to do with dictionaries. It's an internal API feature that's used throughout the framework. The foo.bar syntax is essentially an alias for [foo valueForKey:@"bar"]. Understanding exactly how this method works is one of the first things you need to learn as a cocoa programmer. NSDictionary wouldn't even document valueForKey: at all, except that it changes the behaviour slightly.
Aside from the fact that this thread was resolved quite some days ago, your analysis is factually incorrect, depending on what you mean by "alias". 'foo.bar' does not execute '[foo valueForKey:@bar"]' but rather invokes the method '[foo bar]' directly. OTOH, the default implementation *in NSObject* of 'valueForKey:' invokes a method whose name matches the key (i.e. '[foo bar]') if it exists. Using "alias" for either of these is perhaps torturing the word beyond helpfulness.
Also, NSDictionary changes the behavior of 'valueForKey:' radically, not so much "slightly". It changes the meaning of the parameter from something that's translated into a method name to something that's translated to a dictionary key (unless preceded by a "@").
Further, I'd suggest that another important reason it's documented is that it specifies *how* NSDictionary is KVC compliant, since its compliance is semantically different from that of the class it's inheriting from (namely NSObject). (This fact would be better documented at the start of the class reference, rather than being implied by the 'valueForKey:' method description.)
_______________________________________________
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