IOS compare NSUInteger with NSInteger

I try to compare with numerical values ​​with each other, but I get the warning "Comparison of integers of different signs:" NSInteger "(aka" inti ") and" NSUInteger "(aka" unsigned int ").

This is logical, as I do it;). But how can I fix this warning. This is the code that triggers the warning:

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

The page may be -1, so this is NSInteger, but count returns NSUInteger.

+4
source share
1 answer

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

Then you compare the same types.

if (page >= self.controllers.count || page == NSNotFound)
    return;
+8
source

Source: https://habr.com/ru/post/1527443/


All Articles