jack Nick
jack Nick

Reputation: 13

Bool function for xcode

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");
    }
}

Upvotes: 1

Views: 6394

Answers (2)

Marcelo Cantos
Marcelo Cantos

Reputation: 186118

You need to call the method (not function), and you don't need to compare to YES. The if statement does that implicitly:

if ([self checkForWin]) …

Also note that checkForWin has a problem: it doesn't return anything if the if statement fails. It should be simply:

- (BOOL)checkForWin{
    return [[dictionary valueForKey:[cowsShuffled objectAtIndex:cowsCard]] intValue] == 2;
}

Footnote: Strictly speaking, if (x) … isn't exactly the same as if (x == YES) …. It's actually closer to if (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).

Upvotes: 7

DrummerB
DrummerB

Reputation: 40221

Your method call is wrong. You call a method like this: [object method].

In your case [self checkForWin].

Upvotes: 1

Related Questions