Created
July 28, 2013 07:45
-
-
Save PavelGnatyuk/6097854 to your computer and use it in GitHub Desktop.
Objective-C run-time is used to add a new method to an existing class.
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> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *temp = @"world"; | |
int (^impyBlock)(id, int, int) = ^(id _self, int a, int b) | |
{ | |
return a + b; | |
}; | |
int (*impyFunct)(id, SEL, int, int) = (void*) imp_implementationWithBlock(impyBlock); | |
class_addMethod([temp class], @selector(test:param:), (IMP)impyFunct, "i@:ii"); | |
int result = [temp test:1 param:2]; | |
NSLog(@"result = %i", result); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment