3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Objective-C] IMP型を実行しようとすると「Too many arguments to function call」で怒られる

Last updated at Posted at 2015-09-22

この記事で書かれていたものと同じだと思う。

以下のようにして 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);
うーん、とりあえず原因と対応方法はわかったけど、今やろうとしてることからするとこれは結構めんどくさいな・・。どうするか・・。

こんな感じで実装してみた。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?