在目标C中指向BOOL的指针 [英] Pointer to BOOL in Objective C

查看:352
本文介绍了在目标C中指向BOOL的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
BOOL initial = YES;
[invocation setArgument:&initial atIndex:2];

问题:

是否可以在不创建临时变量的情况下将YES传递给setArgument:atIndex:?

Would it be possible to pass YES to setArgument:atIndex: without creating the temporary variable?

我当时在想,也许有一种我不知道的语言构造和/或在运行时中不变的语言构造,总是我可以指出的YES.

I was thinking that maybe there's a language construct I'm not aware of and/or constant in the runtime that is always YES that I can point to.

谢谢!

推荐答案

否,不是以任何干净,可靠的方式.

No, not in any clean, reliable way.

NSInvocation将取消引用您发送的任何指针,并从中复制方法签名指定的长度的数据.您需要在某处获取该信息,以便获取地址,而拥有本地变量是最好的方法.

NSInvocation will dereference whatever pointer you send it and copy data of length specified by the method signature out of it. You need to have that information somewhere so you can get an address to it, and having the local variable as you have is the best way to do so.

这篇关于在目标C中指向BOOL的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆