Last active
August 29, 2015 13:56
-
-
Save JensAyton/9010577 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 <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