Skip to content

Instantly share code, notes, and snippets.

@iamleeg
Created March 22, 2012 01:51
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamleeg/2155086 to your computer and use it in GitHub Desktop.
Save iamleeg/2155086 to your computer and use it in GitHub Desktop.
The pile of poo Objective-C method
#import <Foundation/Foundation.h>
@interface A: NSObject
@end
@implementation A
void pileOfPoo(id self, SEL _cmd) {
NSLog(@"💩");
}
+ (BOOL)resolveInstanceMethod: (SEL)name {
if ([NSStringFromSelector(name) isEqualToString: @"💩"]) {
class_addMethod([self class], name, (IMP)pileOfPoo, "v@:");
return YES;
} else return NO;
}
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
A *a = [[A alloc] init];
SEL aSelector = NSSelectorFromString(@"💩");
[a performSelector: aSelector];
}
return 0;
}
@diederich
Copy link

Who's A? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment