Created
March 22, 2012 01:51
-
-
Save iamleeg/2155086 to your computer and use it in GitHub Desktop.
The pile of poo Objective-C method
This file contains hidden or 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> | |
@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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Who's A? :-)