Determining if an Objective-C method is variadic during runtime

断了今生、忘了曾经 提交于 2019-12-22 07:53:30

问题


Is there a way to find out -- at runtime -- whether a given method is of variadic type? Something like method_getTypeEncoding(); that won't tell me whether a method accepts variable number of arguments. Or is there maybe a trick to tell so?


回答1:


Robert's comment is correct. Consider:

@interface Boogity
@end
@implementation Boogity
- (void)methodWithOneIntArg:(int)a {;}
- (void)variadicMethodWithIDSentinel:(id)a, ... {;}
@end

Running strings on the resulting binary produces (there was also the stock main()):

strings asdfasdfasdf 
Boogity
methodWithOneIntArg:
variadicMethodWithIDSentinel:
v20@0:8i16
v24@0:8@16
Hello, World!

If I change the variadic method to be declared as - (void)variadicMethodWithIDSentinel:(int)a, ..., the strings output becomes:

Boogity
methodWithOneIntArg:
variadicMethodWithIDSentinel:
v20@0:8i16
Hello, World!

So, no, no way to tell.



来源:https://stackoverflow.com/questions/11511585/determining-if-an-objective-c-method-is-variadic-during-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!