この記事で書かれていたものと同じだと思う。
以下のようにして IMP
型の実装を取得して実行しようとするとタイトルのように怒られた。
NSString *methodName = @"anyMethod:";
SEL sel = NSSelectorFromString(methodName);
CGFloat val = 0.5;
IMP imp = [AnyClass instanceMethodForSelector:sel];
imp(anyClassInstance, sel, val); // <- ここで怒られる(Too many arguments to function call)
上記記事と同じように、適切にキャストしてやることで実行できた。どうやら Xcode6
からの変更らしい。
((void (*)(id, SEL, CGFloat))imp)(anyClassInstance, sel, val);
こんな感じで実装してみた。