NSUInteger index = [self.objects indexOfObject:obj];
if (index == NSNotFound) {
// Success! Note: NSNotFound internally uses NSIntegerMax
}
if (index == NSUIntegerMax) {
// Fails!
}
Why? I’m suppose to get an unsigned value as a result of indexOfObject. So, naturally, i was assuming that if the object is not found, it will return NSUIntegerMax instead of NSIntegerMax. Is this a bug, or is there a logical explanation for this behavior.
Perhaps
NSNotFoundcan be used in contexts that useNSInteger. It is also safer, in case someone declares index asNSIntegerinstead ofNSUInteger.At most, one could say that it’s odd that
NSNotFoundis defined asNSIntegerMax, but it’s certainly not a bug.