Thilina Chamath Hewagama
Thilina Chamath Hewagama

Reputation: 9040

Get all values of the given key using NSPredicate

This is my array,

NSArray *peopleArray = @[
@{@"name":@"Albert",@"age":@"23"},
@{@"name":@"Bruce",@"age":@"25"},
@{@"name":@"Christopher",@"age":@"56"},
@{@"name":@"Hardy",@"age":@"38"},
@{@"name":@"Marlon",@"age":@"20"},
];

I want to get all the names in the above array, using NSPredicates.

NSArray *names = ;//
//Albert,Bruce,Christopher,Hardy,Marlon

Upvotes: 3

Views: 644

Answers (1)

Wain
Wain

Reputation: 119031

Don't use a predicate to extract all of the names, use KVC instead:

NSArray *names = [peopleArray valueForKey:@"name"];

Now that you have the array of names you can use a predicate to filter it if required.

Upvotes: 8

Related Questions