Skip to content

Instantly share code, notes, and snippets.

@jweinberg
Created October 4, 2011 12:47
Show Gist options
  • Save jweinberg/1261555 to your computer and use it in GitHub Desktop.
Save jweinberg/1261555 to your computer and use it in GitHub Desktop.
#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