Hugo Hugo - 6 months ago 30
Objective-C Question

NSMutableArray all values for one key (Kinvey)

I have a NSMutableArray and I add objects (from Kinvey) to it by doing this:

KCSQuery* query = [KCSQuery query];

[self.store queryWithQuery:query withCompletionBlock:^(NSArray *objects, NSError *error) {

if (error == nil) {

[mutableArray removeAllObjects];
[mutableArray addObjectsFromArray:objects];
}

} withProgressBlock:nil];


Now, I need an array that contains all the objects for just one key, for example, an array of all the ids of the objects inside the mutableArray.

Any ideas? Thanks in advance.

Answer

if your mutableArray is an array of dictionaries then you can get all the objects for same key from that mutableArray.

// assuming that you want to retrieve all the "firstName" name from array
NSArray *fnameArray=[mutableArray valueForKey:@"firstName"];
NSLog(@"First Name Array : %@",fnameArray);

Please post some data of your mutableArray so i can give you proper solution.