Cacheing optimisation in valueForKey:
Cacheing optimisation in valueForKey:
- Subject: Cacheing optimisation in valueForKey:
- From: Tom <email@hidden>
- Date: Sun, 14 Mar 2010 20:23:54 +1000
Hi everyone,
I'm having a problem with the interaction of method swizzling and KVC in some experimental stuff that I'm working on: http://github.com/tomdalling/AspectObjectiveC
Let's say there is a method like -(double)fahrenheit;. When I change the implementation of the method with method_setImplementation() and call [someObj fahrenheit] it works fine and calls the new implementation that I've set. However, if I call [someObj valueForKey:@"fahrenheit"] it calls the old implementation. The problem seems to be that valueForKey: caches the implementation of the method for performance reasons: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/KeyValueCoding/Concepts/Performance.html#//apple_ref/doc/uid/20002175-CJBDBHCB
If the method is swizzled before valueForKey: is called for the first time, then the new implementation gets cached, otherwise the old implementation gets cached. This pretty much means that KVC accessor methods need to be swizzled ASAP after application startup, and never changed after that. I want to me able to swizzle any method at any time and have it always call the new implementation.
Is there any way around this? Are the any undocumented methods I could call to invalidate the cache used by valueForKey:? Is there a way to disable the cacheing? Nasty hack solutions are welcome, as the code is experimental anyway.
--Tom
_______________________________________________
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