• 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: efficient searching of arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: efficient searching of arrays


  • Subject: Re: efficient searching of arrays
  • From: Mike Abdullah <email@hidden>
  • Date: Mon, 28 Aug 2006 22:26:17 +0100

Thanks for the various suggestions guys. In the end, the simple approach of using an NSDictionary as someone suggested seems best for this scenario.

Mike.

On 14 Aug 2006, at 20:21, Mike Abdullah wrote:

Let's say I have an NSArray of several hundred instances of MyObject. MyObject has a simple accessor method:

- (long)objectID;

I want to find the instance of MyObject whose objectID is 204. What would be the best way of doing this? At present, the only thing I can really think of is:

NSEnumerator *objectsEnumerator = [myArray objectEnumerator];
MyObject *anObject;

while (anObject = [objectsEnumerator nextObject])
{
	if ([anObject objectID] == 204)
		return anObject;
}

However this seems a little clunky. Is there a better way of doing things in Cocoa that I haven't come across?

Mike.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >efficient searching of arrays (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: Responding to a double-click in a table
  • Next by Date: NSSearchField Case Insensitive
  • Previous by thread: Re: efficient searching of arrays
  • Next by thread: Newbee: Problems with info.plist
  • Index(es):
    • Date
    • Thread