• 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: Filter an array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filter an array


  • Subject: Re: Filter an array
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 28 Jul 2011 16:21:23 -0700

On Jul 28, 2011, at 1:35 PM, Chris Paveglio wrote:

> I'm looking at using: - (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate

I was going to suggest using a block to filter, but it seems that Foundation collections still don’t implement the standard functional operators like ‘map’ and ‘filter' found in lots of other languages. Which is too bad, since otherwise you could write it compactly as

NSArray* filtered = [paths filter: ^(NSString path){
	return [validExtensions containsObject: path.pathExtension.lowercaseString];
}];

There’s -indexesOfObjectsWithOptions:passingTest:, as Kyle pointed out, but that adds another step of generating and using an index-set.

I found the lack of -map so annoying that I wrote a category method for it in my current project...

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Filter an array (From: Chris Paveglio <email@hidden>)

  • Prev by Date: Re: UI like Transmission BT
  • Next by Date: Re: UI like Transmission BT
  • Previous by thread: Re: Filter an array
  • Next by thread: Return causes EXC_BAD_ACCESS
  • Index(es):
    • Date
    • Thread