Skip to content

Instantly share code, notes, and snippets.

@zmcartor
Created April 17, 2018 15:25
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 zmcartor/fde486bae6531971ec62affe01070dd7 to your computer and use it in GitHub Desktop.
Save zmcartor/fde486bae6531971ec62affe01070dd7 to your computer and use it in GitHub Desktop.
Dynamic Instance Method ObjC
+ (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