Op 11-11-2010 14:11, Graham Cox schreef:
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.
It might well be that I forgot to implement change notification in my
wrapper for setObject:forKey: breaking KVO compliance. I'll try that out.
Regards,
Remco Poelstra
_______________________________________________
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]