uspython
uspython

Reputation: 563

Filtering NSArray of NSDictionaries using NSPredicate

I have an array like this:


NSArray* myArray=[NSArray arrayWithObjects:
                      [NSDictionary dictionaryWithObjectsAndKeys:@"123",@"imageid",@"Jeff",@"imagename", nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"234",@"imageid",@"Sophie",@"imagename", nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"456",@"imageid",@"David",@"imagename", nil]
                      , nil];

I wanna get a target array which contains like :
{ 123,234,456 }
How to do this using NSPredicate

Upvotes: 1

Views: 614

Answers (1)

iDev
iDev

Reputation: 23278

Try this. You may not need NSPredicate for this.

NSArray *targetArray = [myArray valueForKey:@"imageid"];

Update: For better understanding of valueForKey, please refer apple documentation of NSArray

Upvotes: 3

Related Questions