问题
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