Theocacao
Leopard
Design Element
Comment on "Add Methods at Runtime in Objective-C"
by Jon Hess — Oct 26
Err, when I said "some known class" that isn't really what I meant. I meant, if you want to specialize the behaviour of some specific object(s), but not all objects, and you only know their partial type. By using the methods outlined in my comment, and this post, you could dynamically override the method of the unknown object.

This is much cleaner than poseAs:. For example, if you posed as window, and did something special in sendEvent: (Let's not forget this would be a hack), your sendEvent: might not get invoked for every event for some subclasses of window. If you dynamically created a class, added a sendEvent: method, and swtiched the window you were interested in to be a member of your class, you could intercept *all* of the events heading to that window. This is much more correct, and percise than poseAs:.
Back to "Add Methods at Runtime in Objective-C"
Design Element

Copyright © Scott Stevenson 2004-2015