在 Objective-C 中使用 BOOL 变量时发出警告

发布于 2024-12-18 18:00:30 字数 446 浏览 2 评论 0原文

我试图将我的 BOOL 变量初始化为 YES,但它给了我这个警告..不太确定该怎么做..它似乎仍然工作正常,但只是想知道如何摆脱警告。

我已经像这样初始化了标头中的变量

//.h

BOOL *removeActivityIndicator;
//..
@property (nonatomic, assign) BOOL *removeActivityIndicator;

然后我尝试将其设置为 YES (这也是我收到警告的地方)

self.removeActivityIndicator = YES;

警告说:

传递“BOOL”(又名 'signed char')到'BOOL *'类型的参数(又名'signed char *')

I am trying to initalize my BOOL variable to YES but its giving me this warning.. not quite sure what to do.. it still seems to be working fine but just wondering how I can get rid of the warning.

I have initalize the variable in the header like this

//.h

BOOL *removeActivityIndicator;
//..
@property (nonatomic, assign) BOOL *removeActivityIndicator;

Then I try to set it to YES like so (this is also where I get the warning)

self.removeActivityIndicator = YES;

The warning says :

incompatible integer to pointer conversion passing 'BOOL' (aka
'signed char') to paramater of type 'BOOL *' (aka 'signed char *')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我纯我任性 2024-12-25 18:00:31

警告是正确的;您已将变量声明为 BOOL * (指向 BOOL 的指针),这几乎肯定不是您想要的。从声明中删除 *

The warning is correct; you've declared the variable as a BOOL * (a pointer to a BOOL), which is almost certainly not what you want. Remove the * from the declaration.

浅暮の光 2024-12-25 18:00:31

removeActivityIndi​​cator 是一个 char 指针,并且您为其分配了一个 char,因此:

  1. 将其更改为 BOOL removeActivityIndi​​cator;
  2. 取消引用它:*(self.removeActivityIndi​​cator) = YES;

removeActivityIndicator is a char pointer, and you assigns a char to it, so either:

  1. change it to be BOOL removeActivityIndicator;
  2. Dereference it: *(self.removeActivityIndicator) = YES;
陪你搞怪i 2024-12-25 18:00:31

您已经创建了一个指向 BOOL 的指针,它是一种原始类型。删除remoteActivityIndi​​cator前面多余的*

You've made a pointer to a BOOL, which is a primitive type. Remove the extra * in front of remoteActivityIndicator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文