Skip to content

Instantly share code, notes, and snippets.

@mattrajca
Created June 7, 2012 23:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrajca/2892298 to your computer and use it in GitHub Desktop.
Save mattrajca/2892298 to your computer and use it in GitHub Desktop.
playing with imp_implementationWithBlock
//
// imp.m
// imp
//
// Copyright (c) 2012 Matt Rajca. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (void)sayHello;
@end
@implementation Person
- (void)sayHello {
NSLog(@"hello");
}
@end
int main(int argc, const char *argv[])
{
@autoreleasepool {
Person *person = [[Person alloc] init];
[person sayHello];
IMP a = imp_implementationWithBlock(^{
NSLog(@"hello again");
});
class_replaceMethod([Person class], @selector(sayHello), a, NULL);
[person sayHello];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment