Andy
Andy

Reputation: 662

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 some 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... }

Upvotes: 1

Views: 2910

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243166

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.

Upvotes: 2

Related Questions