• 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: [NSArrayController] finding object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSArrayController] finding object


  • Subject: Re: [NSArrayController] finding object
  • From: Miguel Sanchez <email@hidden>
  • Date: Fri, 11 Nov 2005 10:25:28 -0800

arrays respond to
- (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate

so you can execute a predicate to filter the result, but you'll still be doing a linear search. If it's efficiency you want, then also store the objects in a dictionary keyed on the id_number

- Miguel

On Nov 11, 2005, at 2:19 AM, Administrateur internet lutin Ludique wrote:

Hi,

here is the problem.

I've got a arrayController which manage a collection of objects in its NSArray content parameter.

All objects are instances from the same class. This class has several parameters. One of these is "id_number" which stores the unique id number of the object in the database.

I'd like to get a handle on the object with a specific id_numer in the collection.
How can I do that ?


For the time being, th only method i foud is to implement a "response" method in my object class.
- (void) doIHaveThisID: (NSString*) anIdNumber sender: (id) aSender ;
{ if ( [self valueForKey: @"id_number"] == anIdNumber)
[sender iAmTheOne: self] ; }


And in the controller:
  - (void) iAmTheOne: (id) anObject
      { do whatever I whish with anObject now that I found it}

Then by calling
[ [arrayController content] makeObjectsPerformSelector: (sel) "doIHaveThisID"
withObject: self] ;


But I think this technic is quite heavy. There must be something more elegant.

Thanks.

_______________________________________________
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

_______________________________________________ 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: 
 >[NSArrayController] finding object (From: Administrateur internet lutin Ludique <email@hidden>)

  • Prev by Date: Re: How to see the arguments of methods from the stack trace during debugging
  • Next by Date: NSPersistentDocument SQL Save As
  • Previous by thread: [NSArrayController] finding object
  • Next by thread: [Binding] NSObjectController content
  • Index(es):
    • Date
    • Thread