• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Returning a specific key's value for all members of a dict in an array.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Returning a specific key's value for all members of a dict in an array.
      • From: Alex Zavatone <email@hidden>
References: 
 >Returning a specific key's value for all members of a dict in an array. (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Returning a specific key's value for all members of a dict in an array.
  • Next by Date: Re: Returning a specific key's value for all members of a dict in an array.
  • Previous by thread: Returning a specific key's value for all members of a dict in an array.
  • Next by thread: Re: Returning a specific key's value for all members of a dict in an array.
  • Index(es):
    • Date
    • Thread