People,
When an object is not found in the array, indexOfObject does NOT return garbage. Many systems return an index of -1 if the item is not found.
However, in IOS - since indexOfObject returns UNSIGNED int (aka NSUInteger), the returned index must be greater than or equal to zero. Since null is a valid index, there is no way to tell the caller that the object was not found - except returning an agreed constant value that we can all check. This consistent consistent value is called NSNotFound.
Method:
- (NSUInteger)indexOfObject:(id)anObject;
will return NSNotFound if the object was not in the array. NSNotFound is a very large POSITIVE integer (usually 1 minus the maximum int value on the platform).
joe Jan 26 '13 at 14:52 2013-01-26 14:52
source share