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?
Determining if an Objective-C method is variadic during runtime
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.
© 2022 - 2024 — McMap. All rights reserved.
method_getNumberOfArguments()
on a veridic method? I've never tried it, but maybe it returns a special value (like -1 or something)? See alsomethod_copyArgumentType()
. – Heelpostmethod_getNumberOfArguments
returns minimal count, just as if it was normal method. – Benedic