• 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: Chris Hanson <email@hidden>
  • Date: Fri, 17 Feb 2006 19:14:48 -0800

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];

...

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.

  -- Chris

_______________________________________________
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: Andre <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)

  • Prev by Date: [CORE DATA] Reinitializing NSManagedObject after redo?
  • Next by Date: Re: Attributed string not displaying with effects of attributes in an NSTextView...
  • 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