I would like to swizzle an object method after the object has been created.
Example:
@interface MyObj: NSObject
-(NSString*) foo;
-(NSString*) bar;
@end
@implementation MyObj
-(NSString*) foo {return @"foo";}
-(NSString*) bar {return @"bar";}
@end
void Swizzle(object, SEL source, SEL, dest);
...
MyObj* obj = [[[MyObj alloc] init] autorelease];
NSLog(@"%@", [obj foo]);
Swizzle(obj, @selector(foo), @selector(bar));
NSLog(@"%@", [obj foo]);
Output:
foo
bar
I have looked at lots of examples of swizzling before an object is created. However as you can see I want to swizzle after an object is created.
This is because I want to track objects that are going to release (like NSThread). I don't want to swizzle NSObject dealloc because that seems overkill. I would rather swizzle only the objects I am trying to track.