views:

46

answers:

4

i am having array called stored and i want to access thier indexes so that i can select them individually to do my operations...

if i want to print thier indexes what should i do?....

+1  A: 

use NSArray's indexOfObject: method. Such as the following:

NSUInteger fooIndex = [someArray indexOfObject: someObject];
jer
A: 

You can get a list of the indexes by using the count method which returns the number of elements in the array:

int numElements = [myArray count];

I'll leave it as an exercise to print out the actual index values :)

ennuikiller
A: 

This article has some great examples of how to iterate over an array. Then, inside the loop, you can use NSLog to print the index.

Topher Fangio
A: 
int totalElements = [anArray count];
for(int i=0; i < totalElements; i++)
{
    data = [myArray indexOfObject:i];
}

The above code will give you the data if you pass in the index

NSString *haystackText = @"Hello World";
int totalElements = [anArray count];
for(int i=0; i < totalElements; i++)
{
    BOOL result = [haystackText caseInsensitiveCompare:[myArray objectAtIndex:i] == NSOrderedSame;
    if(result)
    {
         NSUInteger fooIndex = [myArray indexOfObject: haystackText];
         return fooIndex;
    }
}

The code above will first find the element in the array and if it exists then return the index.

software is fun