Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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;
- }
Add Comment
Please, Sign In to add comment