On Nov 12, 2010, at 11:13, Remco Poelstra wrote:

> Otherwise the valueForKey is called on my wrapper, instead of the dictionary 
> that contains the real keys. I don't see how else the KVC logic should find 
> out about that instance variable.

The dictionary is a private implementation detail of your wrapper class. The 
"KVC logic" knows nothing about it. As far as KVC is concerned, it's your 
wrapper class that has undefined keys, and that's why execution ends up at your 
wrapper class's 'valueForUndefinedKey:' method.

That method, which you write, has the knowledge to go get property values from 
the private dictionary (and to "fetch" the values first as necessary).

Incidentally, this means that your "fetch" completion code should set the 
fetched value via 'setValue:forKey:' *on the wrapper object*, not by putting 
the value directly in the dictionary. Otherwise, the wrapper object won't be 
properly KVO compliant.

I guess what's confusing, in this discussion, is that there are two general 
strategies for doing what you want:

1. Subclass NSDictionary, and use *no* wrapper. In that case, you'd have to 
override 'valueForKey:', which is probably not a very good idea. Also, 
subclassing into the NSDictionary class cluster itself makes this strategy more 
complicated.

2. Use a wrapper class with a NSDictionary as a private instance variable. In 
that case, you override 'valueForUndefinedKey:' so that your wrapper appears to 
the outside world to have the 82 keys you want.

In case 2, which seems like the superior solution, the private dictionary isn't 
being accessed via KVC at all, so the only KVC behavior you're concerned with 
is that of the wrapper.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to