Re: When exactly does a fault get fired?
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