gpt4 book ai didi

objective-c - performSelector 的返回值 :

转载 作者:IT老高 更新时间:2023-10-28 11:48:56 27 4
gpt4 key购买 nike

performSelector 的返回值是什么:如果我传递一个返回原始类型(在对象上)的选择器,例如 NSDateComponents 上的 'week'(它将返回一个 int)?

最佳答案

使用 NSInvocation 返回 float 的示例:

SEL selector = NSSelectorFromString(@"someSelector");
if ([someInstance respondsToSelector:selector]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[[someInstance class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:someInstance];
[invocation invoke];
float returnValue;
[invocation getReturnValue:&returnValue];
NSLog(@"Returned %f", returnValue);
}

关于objective-c - performSelector 的返回值 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6492033/

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