|
Version: 1.0 Posted: 2006-08-01 Build Requirements: Leopard Preview Runtime Requirements: Leopard Preview Download Sample (MethodReplacement.zip, 38.6K) |
||||
DescriptionObjective C 2.0 compatible class_poseAs() replacement. This demonstrates how to replace a method in an existing Objective C class, and how to call the old version without having to store IMP function pointers in a global. The trick is to define a category on the class whose method you want to replace. In the category, declare and implement a method with the same signature as the replaced method. In the +load method of the category, look up the original and replacement methods using class_getInstanceMethod(), then call method_exchangeImplementations(). Subsequent calls to the original method will call the replacement method, and an apparently recursive call to the replacement method will call the original method. Document Revision History
|
|