How to find the index value of an array in object c

Possible duplicate:
Getting object pointer from NSArray?

I have one array and one row. The name of the array is "Array1", the name of the string is "String". Now I have this value lower in "Array1".

"array1 = [[NSMutableArray alloc]initWithObjects:@"A",@"b",@"c",@"d",@"e", nil];" 

The value of my string is "A"

Now I want to compare these strings and arrays. And I want to display the index value of the array.

How can i do this. Please help me. Thanks in advance.

+4
source share
5 answers
 int i; for (i = 0; i < [myArray count]; i++) { id myArrayElement = [myArray objectAtIndex:i]; ...do something useful with myArrayElement }` 

You can iterate through NSMutableArray and find the location of the specific use of the object

  int indexValue = [myArray indexOfObject:yourString]; 
+13
source

I'm not sure if this is what you are looking for, but it is possible:

 int index = [array1 indexOfObject:String]; 
+13
source

Try it,

 if([array1 containsObject: yourString]) { int index = [array1 indexOfObject:yourString]; } 
+4
source

Using

 NSString * String=@ "A"; NSInteger index = [array1 indexOfObject:String]; 

NOTE. Never use a variable name with capital String ; it must be a String .

+2
source

Check

 int index = [yourArray indexOfObject:yourObject]; 

is correct for NSString objects and some other types of objects.

When you have implemented the class yourself and want to get the index of the object in the array, you must implement the method

 - (BOOL)isEqual:(id)anObject 
0
source

All Articles