• 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: Graham Cox <email@hidden>
  • Date: Fri, 12 Nov 2010 00:11:50 +1100

On 12/11/2010, at 12:01 AM, Remco Poelstra wrote:

> Seems so :) I just tried that and observing the change of properties is now non-functional, as the request for observing is not forwarded to the NSDictionary behind my own object. Seems I've to override a whole lot of methods to forward them all to the backingstore.


You seem to be overthinking this.

Just write a wrapper for -setObject:forKey: and -valueForKey:  The first just calls the same method on its (mutable) dictionary, the second can first check for whether the value is actually present and if not kick off some task to fetch it, or else just get it from the dictionary and return it. You don't need to do any general purpose forwarding, unless your object has to look exactly like a dictionary externally for some reason, but even then the few methods a dictionary implements are still easy to just write wrappers for individually rather than doing a general forwarding.

This is an extremely common implementation for caching and I've rarely found it more complicated than this.

--Graham

 _______________________________________________

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

  • Follow-Ups:
    • Re: Detecting reading a key in KVC
      • From: Ken Thomases <email@hidden>
    • Re: Detecting reading a key in KVC
      • From: Remco Poelstra <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>)

  • Prev by Date: Re: Detecting reading a key in KVC
  • Next by Date: Re: Detecting reading a key in KVC
  • Previous by thread: Re: Detecting reading a key in KVC
  • Next by thread: Re: Detecting reading a key in KVC
  • Index(es):
    • Date
    • Thread