Skip to content

Instantly share code, notes, and snippets.

@JensAyton
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensAyton/9010577 to your computer and use it in GitHub Desktop.
Save JensAyton/9010577 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Test: NSObject
@end
@interface Test (Dynamic)
- (void)foo:(float)x :(float)y;
@end
@implementation Test
+ (BOOL)resolveInstanceMethod:(SEL)sel
{
if (sel == @selector(foo::))
{
IMP imp = imp_implementationWithBlock(^(Test *self, float x, float y){
NSLog(@"%g, %g", x, y);
});
class_addMethod(self, sel, imp, (const char []){ _C_ID, _C_SEL, _C_FLT, _C_FLT });
return YES;
}
else
{
return [super resolveInstanceMethod:sel];
}
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool
{
Test *t = [[Test alloc] init];
[t foo:5 :42.3];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment