Created
October 4, 2011 12:47
-
-
Save jweinberg/1261555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
@interface Foo : NSObject | |
int ivar; | |
- (void)doThings; | |
@end | |
@implementation Foo | |
- (id)initWithThings:(int)thing; | |
{ | |
if ((self = [super init])) | |
{ | |
ivar = thing; | |
} | |
return self; | |
} | |
- (void)doThings; | |
{ | |
NSLog(@"Things %d!", ivar); | |
} | |
@end | |
int main() | |
{ | |
Class fooClass = objc_getClass("Foo"); | |
Foo *foo = class_createInstance(fooClass, 0); | |
IMP init = class_getMethodImplementation(fooClass, @selector(initWithThings:)); | |
init(foo, @selector(init), 1000); | |
IMP doStuff = class_getMethodImplementation(fooClass, @selector(doThings)); | |
doStuff(foo, @selector(doThings)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment