NSNotFound is defined as NSIntegerMax, which has different values on 32-bit and 64-bit, this brings a lot of inconvenience for persistent and distributed env. Why not define it as -1?
PS, In ObjC and Cocoa, some indexOf... methods returns NSNotFound but some returns -1, is there a reason these results are inconsistent.
This note from the docs is probably relevant:
Special Considerations
Prior to Mac OS X v10.5,
NSNotFound
was defined as0x7fffffff
. For 32-bit systems, this was effectively the same asNSIntegerMax
. To support 64-bit environments,NSNotFound
is now formally defined asNSIntegerMax
. This means, however, that the value is different in 32-bit and 64-bit environments.
Well the answer probably isn't because it is sometimes returned as an unsigned value - in Objective-C conversions between signed and unsigned are effectively bit-copies so you can compare an unsigned to -1 and get the answer you expect (the values is all ones - -1 as signed, maximum integer as unsigned). See answer to this question.
So we come to your second part of the question, why in the inconsistency? Well variety is the spice of life, or put another way there's nowt so queer as folk - people are just inconsistent, no more complicated than that!
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