• 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: Selecting an object based on the value of one of its attributes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selecting an object based on the value of one of its attributes


  • Subject: Re: Selecting an object based on the value of one of its attributes
  • From: Graham Cox <email@hidden>
  • Date: Wed, 28 Apr 2010 12:53:09 +1000

On 28/04/2010, at 12:37 PM, Lynn Barton wrote:

> Newbie question: Consider an array of dictionary objects, all of the same class. One of the ivars of that class is an NSString which is unique for each instance. Does there already exist a method that will identify the one dictionary object that has a given value of that ivar, without me having to write code to examine all of the objects one by one? I have searched the documentation without finding such a method.
> Lynn Barton


You could use NSPredicate to "filter" your collection based on your unique string property being equal to the one sought. If they are unique it will return exactly one item (or none, if it doesn't exist).

See [NSArray filteredArrayUsingPredicate:]

It's unclear whether that would be actually any faster than doing a linear search yourself - it might be slower, in that it wouldn't return as soon as it found the item, but would always check every element.

--Graham


_______________________________________________

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: Selecting an object based on the value of one of its attributes
      • From: Roland King <email@hidden>
References: 
 >Selecting an object based on the value of one of its attributes (From: Lynn Barton <email@hidden>)

  • Prev by Date: Selecting an object based on the value of one of its attributes
  • Next by Date: Re: Selecting an object based on the value of one of its attributes
  • Previous by thread: Selecting an object based on the value of one of its attributes
  • Next by thread: Re: Selecting an object based on the value of one of its attributes
  • Index(es):
    • Date
    • Thread