开发者

Comparison between pointer and integer error

开发者 https://www.devze.com 2022-12-29 04:10 出处:网络
I\'ve got the following line of code in one of my Objective-C methods: if (self.rule.sunday == YES) { do some stuff... }

I've got the following line of code in one of my Objective-C methods:

if (self.rule.sunday == YES) { do some stuff... }

The line produces the following compiler warning:

Comparison between pointer and integer

It's just a warning, so it's not life-threatening, but it's driving me nuts. Clearly there is so开发者_运维百科me basic concept about integers, pointers, and/or booleans that I am missing. Can somebody please enlighten me so I can fix my code?

As usual, thanks in advance for your help.

UPDATE: For reference, the corrected code looks like this:

if ([self.rule.sunday boolValue] == YES) { do some stuf... }


self.rule.sunday is returning an object reference. YES is not an object, it's an unsigned char. So you're comparing an object reference (ie, a memory address) to 1. Of course it's going to complain at you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号