在 Objective-C 中使用 BOOL 变量时发出警告
我试图将我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
警告是正确的;您已将变量声明为
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.removeActivityIndicator
是一个 char 指针,并且您为其分配了一个 char,因此:BOOL removeActivityIndicator;
*(self.removeActivityIndicator) = YES;
removeActivityIndicator
is a char pointer, and you assigns a char to it, so either:BOOL removeActivityIndicator;
*(self.removeActivityIndicator) = YES;
您已经创建了一个指向
BOOL
的指针,它是一种原始类型。删除remoteActivityIndicator
前面多余的*
。You've made a pointer to a
BOOL
, which is a primitive type. Remove the extra*
in front ofremoteActivityIndicator
.