Friday, May 31, 2013

NSArray indexOfObjectIdenticalTo inRange example in Objective C (iOS).

NSArray indexOfObjectIdenticalTo inRange

Returns the lowest index within a specified range whose corresponding array value is equal to a given object .

- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range

An object.
The range of indexes in the array within which to search for anObject.

Return Value
The lowest index within range whose corresponding array value is identical to anObject. If none of the objects within range is identical to anObject, returns NSNotFound.

Discussion of [NSArray indexOfObjectIdenticalTo inRange]
Objects are considered identical if their object addresses are the same.

NSArray indexOfObjectIdenticalTo inRange example.
NSArray* arrFruits = [NSArray arrayWithObjects:@"Apple", @"Orange", @"Banana", @"Watermelon", @"Cherry", @"Strawberry", @"Pineapple", nil];

idx = [arrFruits indexOfObjectIdenticalTo:@"Banana"];
idx = [arrFruits indexOfObjectIdenticalTo:@"Cherry" inRange:NSMakeRange(0, 5)];

Example of [NSArray indexOfObjectIdenticalTo inRange].
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range;
NSLog(@"%lu", [demo indexOfObjectIdenticalTo:@"two" inRange:NSMakeRange(2, 1)]);

End of NSArray indexOfObjectIdenticalTo inRange example article.