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 (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to