0

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?

4 Answers 4

3

(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.

Sign up to request clarification or add additional context in comments.

Comments

1

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)

1 Comment

But the code if ([theQueueArray containsObject:elementName]) works just fine for me
0

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.)

1 Comment

This approach helped me. Thank you!
0

[searchArray containsObject:elementName] you can use it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.