Re: Returning a specific key's value for all members of a dict in an array.
Re: Returning a specific key's value for all members of a dict in an array.
- Subject: Re: Returning a specific key's value for all members of a dict in an array.
- From: Charles Srstka <email@hidden>
- Date: Fri, 30 Mar 2012 18:03:13 -0500
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 (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