gpt4 book ai didi

objective-c - 在运行时确定 Objective-C 方法是否可变

转载 作者:太空狗 更新时间:2023-10-30 03:51:19 24 4
gpt4 key购买 nike

有没有办法在运行时找出给定方法是否为可变类型?类似于method_getTypeEncoding();这不会告诉我一个方法是否接受可变数量的参数。还是有什么诀窍可以告诉我们?

最佳答案

罗伯特的评论是正确的。考虑:

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

在生成的二进制文件上运行 strings(还有常用的 main()):

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

如果我将可变参数方法更改为声明为 - (void)variadicMethodWithIDSentinel:(int)a, ...,则 strings 输出变为:

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

所以,不,没办法说。

关于objective-c - 在运行时确定 Objective-C 方法是否可变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11511585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com