NSNotFound
is defined as NSIntegerMax
, which is defined as LONG_MAX
.
NSRange.location
is defined as a NSUInteger
.
Some Foundation methods return an NSRange
whose location value is NSNotFound
.
So, one often does this comparison:
if (aRange.location == NSNotFound)
But isn't that a comparison between signed and unsigned integers that should generate a warning?
You are comparing an unsigned (64 bit) variable with a signed constant which also fits into the range of the variable (it is not negative). So no need for a warning.
The warnings appear typically when comparing against negative constants or variables on both sides (i.e. one part is or can be negative while the other is only positive or zero).
A side note: NSNotFound is different on 32 bit vs 64 bit platforms, so don't hardcode or store that value anywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With