Skip to content

Instantly share code, notes, and snippets.

@segiddins
Created April 18, 2015 00:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save segiddins/e60ffd0975b01c655d74 to your computer and use it in GitHub Desktop.
I swear, I only did this for an experiment
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
IMP imp = imp_implementationWithBlock(^id(id self, id block, id arg){
NSLog(@"self: %@, arg: %@", self, arg);
return self;
});
class_addMethod([NSObject class], @selector (foo), imp, "@@:@");
NSObject *object = [[NSObject alloc] init];
id ret = [object performSelector:@selector (foo) withObject:@"Hi!"];
NSLog(@"ret: %@", ret);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment