Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS compare NSUInteger to NSInteger

I am trying to compare to numeric values to each other but I get the warning "Comparison of integers of different signs: 'NSInteger' (aka 'inti) and 'NSUInteger' (aka 'unsigned int').

Which is logical since I do that ;). But how do I fix this warning. This is the code that raises the warning:

if (page >= self.controllers.count || page < 0)
    return;

Page can be -1 so it is a NSInteger but count returns a NSUInteger.

like image 706
Haagenti Avatar asked Feb 13 '23 18:02

Haagenti


1 Answers

Instead of using an NSInteger for page and -1, use NSUInteger and NSNotFound where you use -1.

Then you're comparing the same types.

if (page >= self.controllers.count || page == NSNotFound)
    return;
like image 149
Dave Wood Avatar answered Feb 27 '23 03:02

Dave Wood