Created
April 17, 2018 15:25
-
-
Save zmcartor/fde486bae6531971ec62affe01070dd7 to your computer and use it in GitHub Desktop.
Dynamic Instance Method ObjC
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
+ (BOOL)resolveInstanceMethod:(SEL)aSEL { | |
NSString *classname = NSStringFromClass([self class]); | |
NSString *selectorString = [NSString stringWithFormat:@"insaneInstance%@",classname]; | |
SEL ourSelector = NSSelectorFromString(selectorString); | |
if (aSEL == ourSelector) { | |
class_addMethod([self class], aSEL, (IMP)insaneInstanceMethod, "v@:"); | |
return YES; | |
} | |
return [super resolveInstanceMethod:aSEL]; | |
} | |
void insaneInstanceMethod(id self, SEL _cmd) { | |
NSLog(@"insane instance method has been added!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment