If statetement : I found something strange. Why does my second ‘if’ is equal to no?
int a = bookSettings.tracks.count;
int b = _currentChapter - 1;
NSLog(@"a: %d", a);
NSLog(@"b: %d", b);
if (a > b)
NSLog(@"yes 1");
else NSLog(@"no 1");
if (bookSettings.tracks.count > (_currentChapter -1))
NSLog(@"yes 2");
else NSLog(@"no 2");
and log
a: 27
b: -1
yes 1
no 2
NSArray’s
-countmethod returns anNSUInteger— an unsigned integer.Using
bookSettings.tracks.countin yourifstatement is likely causing both sides of the expression to be cast asNSUInteger. Even though_currentChapter - 1equals -1, as an unsigned integer it is a very large number. So your track count is obviously less than that very large integer, which is why the if statement is yielding “no 2”.