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?....
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?....
use NSArray's indexOfObject:
method. Such as the following:
NSUInteger fooIndex = [someArray indexOfObject: someObject];
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 :)
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.
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.