• 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: When exactly does a fault get fired?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When exactly does a fault get fired?


  • Subject: Re: When exactly does a fault get fired?
  • From: Andre <email@hidden>
  • Date: Fri, 17 Feb 2006 20:24:38 -0800

 Chris Hanson wrote:

Thanks for the reply Chris.

On Feb 17, 2006, at 4:01 PM, email@hidden wrote:

I think a fetch predicate could be easier, but I want the objects only in a specific relationship. Not in the whole store....
Also, at most, I would only pull one object out of the search because each object would have a unique name.
So, I guess the balance to find is, search speed vs. ease of coding....

You can do this easily, since you can use more than one criteria in a predicate. For example, let's say you have Employee and Department entities and you want to find all of the Employee instances in the "Engineering" Department named "Fred":


...

NSManagedObjectContext *context = ...;
NSEntityDescription *employeeEntity = ...;
NSManagedObject *engineeringDepartment = ...;

NSPredicate *engineersNamedFredPredicate = [NSPredicate predicateWithFormat:@"(department = %@) and (name = \"Fred\")", engineeringDepartment];

NSFetchRequest *engineersNamedFredFetch = [[NSFetchRequest alloc] init];
[engineersNamedFredFetch setEntity:employeeEntity];
[engineersNamedFredFetch setPredicate:engineersNamedFredPredicate];


NSError *fetchError;
NSArray *engineersNamedFred = [context executeFetchRequest:engineersNamedFredFetch error:&fetchError];


[engineersNamedFredFetch release];

...
Thanks, I guess I could do that then. I was just worried that if I have a huge number of 'employee' entities, then performance could degrade... is that a concern at all?

If you only want the "first" Employee named "Fred" in the "Engineering" Department by some ordering criteria, you can set a sort descriptor and fetch limit on the fetch request as appropriate.

This should all be doable without pulling objects back from the persistent store and sifting through them by hand.
Ok, I'm going to implement this and see how it goes.

Hmm, I'm wondering, if I retrieve a set of objects using KVC for a relation like [engineering mutableSetValueForKey:@"employees"] does it use the same mechanism as the fetch predicate like in your example : (department = %@), with coredata knowing 'department' is an to-many relationship... so the performance is the same? (I know we shouldn't rely too much on implementation details as they change, but its more for performance question)

Again, thanks for all the help, its really appreciated.

Andre
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


  • Follow-Ups:
    • Re: When exactly does a fault get fired?
      • From: Chris Hanson <email@hidden>
References: 
 >When exactly does a fault get fired? (From: email@hidden)
 >Re: When exactly does a fault get fired? (From: AurĂ©lien HugelĂ© <email@hidden>)
 >Re: When exactly does a fault get fired? (From: Andre <email@hidden>)
 >Re: When exactly does a fault get fired? (From: Chris Hanson <email@hidden>)
 >Re: When exactly does a fault get fired? (From: mmalcolm crawford <email@hidden>)
 >Re: When exactly does a fault get fired? (From: email@hidden)
 >Re: When exactly does a fault get fired? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Horrible documentation
  • Next by Date: Buld and running the simplest things fail...
  • Previous by thread: Re: When exactly does a fault get fired?
  • Next by thread: Re: When exactly does a fault get fired?
  • Index(es):
    • Date
    • Thread