• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting reading a key in KVC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Detecting reading a key in KVC (From: Remco Poelstra <email@hidden>)
 >Re: Detecting reading a key in KVC (From: "email@hidden" <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Quincey Morris <email@hidden>)
 >Re: Detecting reading a key in KVC (From: "email@hidden" <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Quincey Morris <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Remco Poelstra <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Graham Cox <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Remco Poelstra <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Graham Cox <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Ken Thomases <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Graham Cox <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Ken Thomases <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Remco Poelstra <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Detecting reading a key in KVC
  • Next by Date: Core Data: During Migration, should use Primitive Accessors only?
  • Previous by thread: Re: Detecting reading a key in KVC
  • Next by thread: Re: Detecting reading a key in KVC
  • Index(es):
    • Date
    • Thread