Returning a specific key's value for all members of a dict in an array.
Returning a specific key's value for all members of a dict in an array.
- Subject: Returning a specific key's value for all members of a dict in an array.
- From: Alex Zavatone <email@hidden>
- Date: Fri, 30 Mar 2012 18:38:17 -0400
Hi all.
I've got an array that has KVP dicts in each record that report a Name property and a GPS string.
Is there any lovely one liner that is able to return the values of a specific property for all elements in the array of dicts as an array of those values?
Like so:
I'd like to go from:
myArray:
(
{
Name = "Puppies";
geocode = "42.40283381228625, -71.2597588506239";
},
{
Name = "Kittens";
geocode = "42.40283381228625, -71.2597588506239";
}
)
to:
myNameArray:
(
"Puppies",
"Kittens"
)
I know I can do this and add the NSStrings to a NSMutableArray, then convert that to an NSArray, but I was hoping the experts already have this in a much cleaner approach.
for (NSDictionary *myArrayMember in myArray) {
NSString *nameValue = [myArrayMember objectForKey:@"Name"];
// add NameValue String to array here.
NSLog(@" %@", nameValue);
}
Thanks in advance,
- Alex Zavatone
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden