Reputation: 12051
I have got an NSMutableArray before adding values to which I check if it's already there and I put this value at index 0. However, if the value is already there, I would like to know it's there at the specific index. This code doesn't work:
if ([theQueueArray containsObject:elementName atIndex:0])
How do you do it right, then?
Upvotes: 0
Views: 1041
Reputation: 2762
You can't query by element name. You'd need a copy of the object your looking for to check like this. You'd need something more like:
if([[theQueryArray objectAtIndex:0] compare: @"elementName"] == NSOrderedSame)
Upvotes: 1
Reputation: 26096
(NSUInteger)indexOfObject:(id)anObject
?
Return Value: The lowest index whose corresponding array value is equal to anObject. If none of the objects in the array is equal to anObject, returns NSNotFound.
Upvotes: 3
Reputation: 71068
Checking if an array "contains" an item at a specific index just sounds like a fancy way of stating the general case of accessing any item from an array at a given index, no?
if ([[theQueueArray objectAtIndex:0] isEqual:elementName]) {
// ...
}
(If this isn't what you mean, consider clarifying the question.)
Upvotes: 0