foo(123) #=> エラー
def foo(v)
end
def bar(v)
bar(123) #=> OK
IMP imp = imp_implementationWithBlock(^(void) { NSLog(@"myMethod"); });
class_addMethod(NSString.class, sel_registerName("myMethod"), imp, "v@:");
[@"String" performSelector:@selector(myMethod)];
自己紹介
黒魔術
メソッドを実行時に生成
foo(123) #=> エラー
def foo(v)
end
def bar(v)
end
bar(123) #=> OK
IMP imp = imp_implementationWithBlock(^(void) { NSLog(@"myMethod"); });
class_addMethod(NSString.class, sel_registerName("myMethod"), imp, "v@:");
[@"String" performSelector:@selector(myMethod)];