Re: Detecting reading a key in KVC
Re: Detecting reading a key in KVC
- Subject: Re: Detecting reading a key in KVC
- From: Quincey Morris <email@hidden>
- Date: Fri, 12 Nov 2010 10:31:00 -0800
On Nov 12, 2010, at 10:16, Quincey Morris wrote:
> - (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;
> }
Oops, sorry, I meant to suggest a slightly different implementation, but forgot. Here's what I had in mind:
static NSSet* knownKeys = [NSSet setWithObjects: ... list of 82 keys your dictionary is allowed to contain ..., nil];
- (id) valueForUndefinedKey: (NSString*) key {
if (![knownKeys containsObject: key])
return [super valueForUndefinedKey: key];
id retVal=[properties objectForKey:key]; // note: NOT 'valueForKey:'
if (!retVal) {
//fetch value from network
//We do not wait for the value
}
return retVal;
}
Alternatively, you could prefill your dictionary with [NSNull null] values for all keys, and test for that instead.
That way you can tell the difference between an invalid key and a key that hasn't been fetched yet.
_______________________________________________
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