How to search through NSMutableArray

I have an NSMutableArray that I need to search for a string and return the key to the array where the string was found. So, for example, if I search for "ipod" and it is the fourth in the array, it will return 3 or any other position that the line is in. What is the best way to do this?

+6
iphone nsmutablearray
source share
2 answers
return [theArray indexOfObject:@"ipod"]; 

Link: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:.

Note that NSMutableArray is inherited from NSArray, so any NSArray methods can be used in NSMutableArray as well.

+9
source share

Again from the documentation: Object passing test index

You need to write a code block that checks the substring in each object: NSString rangeOfString: parameters:

Then you get the index of the object with a substring. You will need to run the string search again for your result, but this should help you with what you need.

+2
source share

All Articles