Re: Detecting reading a key in KVC
Re: Detecting reading a key in KVC
- Subject: Re: Detecting reading a key in KVC
- From: Remco Poelstra <email@hidden>
- Date: Fri, 12 Nov 2010 20:13:33 +0100
Op 12 nov 2010, om 19:16 heeft Quincey Morris het volgende geschreven:
As as been said several times in this thread, you *shouldn't*
override 'valueForKey:', but instead override
'valueForUndefinedKey:' like this:
Is this kind of override ok?:
valueForKey: {
[properties valueForKey:key];
}
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.
@implementation PropertiesController
- (id) valueForUndefinedKey: (NSString*) key {
id retVal=[properties objectForKey:key]; // note: NOT 'valueForKey:'
if (!retVal) {
//fetch value from network
//We do not wait for the value
}
return retVal;
}
@end
If you want to know how control reaches this method, read the
documentation:
http://developer.apple.com/library/mac/#documentation/Cocoa/
Conceptual/KeyValueCoding/Concepts/SearchImplementation.html#//
apple_ref/doc/uid/20000955-CJBBBFFA
Unfortunatly, this does not seem to hold for a NSDictionary. It always
returns something instead of calling valueForUndefinedKey:
Regards,
Remco Poelstra
_______________________________________________
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