1 #import <objc/runtime.h> 2 3 id (*foo_without_bar)(id, SEL); 4 id foo_with_bar(id self, SEL selector) 5 { 6 /* do your work here */ 7 return foo_without_bar(self, selector); 8 } 9 10 // exchange method implementation 11 SEL fooSelector = @selector(foo); 12 Method method = class_getInstanceMethod(class, fooSelector); 13 *(IMP*)&foo_without_bar = 14 method_getImplementation(method); 15