【问题标题】:Is there any way to cast void* to SEL有什么方法可以将 void* 转换为 SEL
【发布时间】:2016-08-22 14:17:35
【问题描述】:

我正在使用 obj-c 运行时从 NSInvocation 获取对象类型和值。而且我不知道该怎么做。

这就是我从 NSInvocation 检索信息的方式 argValue 应该是 void*,指定的索引是 SEL 类型的参数。

[invocation getArgument:argValue atIndex:argIndex];

那么SEL sel = (???)argValue;怎么投呢?

【问题讨论】:

  • 你试过(SEL)argValue吗?
  • @Cy-4AH,感谢您的回答找到:SEL value = nil; [invocation getArgument:&value atIndex:index];

标签: objective-c objective-c-runtime


【解决方案1】:

尝试跟随代码。

- (void)forwardInvocation:(NSInvocation *)anInvocation {
  NSLog(@"%@", NSStringFromSelector(anInvocation.selector));
  NSLog(@"%@", anInvocation);
}

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多