NSArray indexOfObjectIdenticalTo
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject
Parameters
anObject
An object.
Return Value
The lowest index whose corresponding array value is identical to anObject. If none of the objects in the array is identical to anObject, returns NSNotFound.
Discussion of [NSArray indexOfObjectIdenticalTo]
Objects are considered identical if their object addresses are the same.
NSArray indexOfObjectIdenticalTo example.
@interface NSArray (MONStuff)
- (BOOL)mon_containsObject:(id)object;
@end
@implementation NSArray (MONStuff)
- (BOOL)mon_containsObject:(id)object {
return NSNotFound != [self indexOfObjectIdenticalTo:arg];
}
@end
- (BOOL)mon_containsObject:(id)object;
@end
@implementation NSArray (MONStuff)
- (BOOL)mon_containsObject:(id)object {
return NSNotFound != [self indexOfObjectIdenticalTo:arg];
}
@end
Example of [NSArray indexOfObjectIdenticalTo].
if ([array indexOfObjectIdenticalTo: foo] != NSNotFound)
{
// do what you need
}
{
// do what you need
}
NSArray indexOfObjectIdenticalTo example.
NSInteger index = [array indexOfObjectIdenticalTo:otherObject];
if (NSNotFound == index) {
// ... handle not being in array
} else {
// ... do your normal stuff
}
if (NSNotFound == index) {
// ... handle not being in array
} else {
// ... do your normal stuff
}