0

I want get the return value class of an instance in runtime. The thing it's that I have a SEL type var where I store a selector. I have a variable named id _instance that points to an instance that I know it performs the selector. Before perform the method I want to know if I have to do:

NSObject* returnValue=[_instance performSelector:_selector withObject:params.params];

or:

[_instance performSelector:_selector withObject:params.params];

I have read a post where someone explain the way to have that with objective-c runtime:

Method m = class_getClassMethod([_instance class], _selector);

char ret[256];
method_getReturnType(m, ret, 256);
NSLog(@"Return type: %s", ret);

But the outputs is nothing like ret is empty.

Really it can be enough to know if it's a void or have a return type but I don't know where to search. I have read the objective-c runtime reference but the only thing I found is the method_getReturnType.... Any idea?

4

2 に答える 2

2

インスタンスメソッドを探している場合は、class_getInstanceMethodではなくを使用する必要がありますclass_getClassMethod。クラスメソッドとインスタンスメソッドは明らかに異なるものです。

于 2012-05-24T13:56:28.217 に答える
0

しばらく検索したところ、この種のものにSpotifyを使用しているライブラリが見つかりました。名前はMAObjcRuntimeで、ここで見つけることができます。

于 2012-05-31T14:31:38.767 に答える