Tricky of NSUInteger and NSInteger Compare

Ngchiwa Ng
1 min readJan 11, 2018

--

if NSInteger is negative and the value is smaller than NSUInteger,

the result will be like this:

NSInteger intCount = -1;    //smaller valueNSUInteger uIntCount = 100; //bigger valueNSLog(@"%d", intCount > uIntCount); //to be true (-1 > 100)

why -1 > 100 ? hahaha

--

--

Ngchiwa Ng
Ngchiwa Ng

Written by Ngchiwa Ng

Backend/iOS Engineer, rock the world

No responses yet