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/