AhabLives
AhabLives

Reputation: 1468

How to find all values in - Array of plist?

I hope this is clear and thanks in advance,

I would like to change the following line of code from get only values at index 0 to get the values at all existing indexs. I have to move from one array object in my Plist to many Array objects p.s. this line of code is in cellForRowAtIndexPath

    NSArray *myIndexList = [[inPlist objectAtIndex:0] objectForKey:@"myIndex"];
    NSLog( @"data from INDEX !!!!!!!! %@", myIndexList); 

I've been toying with a for loop ....with no luck. -Thanks for the help.

Upvotes: 0

Views: 122

Answers (4)

GregJaskiewicz
GregJaskiewicz

Reputation: 496

The fast enumeration is great, but not when you need to know the index of the item.

for(element *foo in array)
{
  // do stuff
}

vs

[array enumerateObjectUsingBlock:^(element *foo, NSUInteger i, BOOL *stop){
// here you got access to both foo and i, and it is working exactly the same way for loop does

}];

HTH

Upvotes: 0

Michael Mangold
Michael Mangold

Reputation: 1801

If I understand correctly, fast enumeration would be a straightforward tactic. The block-based approach recommended by user846262 is more advanced, but this is a bit easier at first.

Upvotes: 0

rdelmar
rdelmar

Reputation: 104082

If your array is an array of dictionaries, which it seems to be since you're using objectForKey, you can just use valueForKey:

NSArray *myIndexList = [inPlist valueForKey:@"myIndex"];

This will give you all the values for the key "myIndex" in your array.

Upvotes: 1

GregJaskiewicz
GregJaskiewicz

Reputation: 496

enumerate the array.

for instance - (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block;

Upvotes: 1

Related Questions