objective-c - performSelector 的返回值 :

标签 objective-c cocoa-touch cocoa performselector

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/

相关文章:

objective-c - 将 SYMBOL 与我的应用程序集成?

iphone - UIGestureRecognizer 是否适用于 UIWebView?

ios - 在 UIView 顶部添加减法掩码

iphone - 如何在启用自动布局功能的情况下通过代码插入 UIButton - iOS

objective-c - 如何在具有 NSAttributedStrings 的 NSComboBox 中添加自动完成功能

objective-c - 强制 NSTextField 发送 textDidEndEditing

ios - 显示缩略图 UIImageView

ios - 如果 iphone 扬声器有故障/有缺陷,AVAudioSession 实例会发生什么?

objective-c - 将 0 作为枚举选项传递给 Swift 中的 Objective C 函数

ios - 将 NSFetchedResultsController 与 UITableView 中的特定部分相关联