I am practicing some bool functions and I seem to be stuck any help will be appreciated. I must be making some little mistake.
-(BOOL) checkForWin
{
if ([[dictionary valueForKey:[cowsShuffled objectAtIndex:cowsCard]] intValue] == 2{
return YES;
}
}
-(void) moo
{
if (checkForWin == YES) {
NSLog (@"foo");
}
}
You need to call the method (not function), and you don’t need to compare to YES. The
ifstatement does that implicitly:Also note that
checkForWinhas a problem: it doesn’t return anything if theifstatement fails. It should be simply:Footnote: Strictly speaking,
if (x) …isn’t exactly the same asif (x == YES) …. It’s actually closer toif (x != NO) …, but of course that’s the same thing for most intents and purposes (and those for which it isn’t are largely pathological).