-2

All I want to do is check if the NSNumbers at the given indexes in the array gameBoard add up to 3... I am new to Objective-C and I am unsure of all these NSNumbers... Can someone help me out?

This is what I have.... I presume the == is not correct.

if ( [[gameBoard objectAtIndex:0] integerValue] + [[gameBoard objectAtIndex:3] integerValue] + [[gameBoard objectAtIndex:6] integerValue]] == 3);
{
    NSLog(@"k");
}

Also what is the difference between intValue and integerValue? I notice they are both options... Should I use one or the other?

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
kpce
  • 35
  • 9
  • To see the difference between `intValue` and `integerValue`, look at the docs for both. – rmaddy Mar 06 '15 at 22:42
  • You have an extra `]` at the very end of your addition, before the equality comparison operator: `integerValue]] == 3`. Does this code compile? Is that a typo in your post? – Aaron Brager Mar 06 '15 at 22:43

1 Answers1

0

Remove the semicolon and the extra ]:

if ( [[gameBoard objectAtIndex:0] integerValue] + [[gameBoard objectAtIndex:3] integerValue] + [[gameBoard objectAtIndex:6] integerValue] == 3)
{
    NSLog(@"k");
}

Stylistically, you should replace [gameBoard objectAtIndex:0], etc. with gameBoard[0].

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287