Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created June 19, 2014 12:37
Show Gist options
  • Save tarunon/6e00d18cd96f7192fb44 to your computer and use it in GitHub Desktop.
Save tarunon/6e00d18cd96f7192fb44 to your computer and use it in GitHub Desktop.
@implementation NSObject (forSwift)
- (id)__performSelector:(SEL)aSelector
{
Method m = class_getInstanceMethod(self.class, aSelector);
const char *types = method_copyReturnType(m);
if (strcmp("v", types)) {
return [self performSelector:aSelector];
} else {
[self performSelector:aSelector];
return nil;
}
}
- (void)addMethod:(void(^)())rambda
{
id class = [self class];
SEL sel = @selector(hoge);
IMP imp = imp_implementationWithBlock(rambda);
Method method = class_getInstanceMethod(class, sel);
class_addMethod(class, sel, imp, "v");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment