Comparison between pointer and integer error
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.
精彩评论