Re: Returning a specific key's value for all members of a dict in an array.
On Mar 30, 2012, at 5:38 PM, Alex Zavatone wrote:
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
-[NSArray valueForKey:] ? Charles _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Charles Srstka