A fetch request can only fetch one entity at a time, right?
Is that true? Or could I fetch multiple entities at once? If so,开发者_StackOverflow中文版 how would that look like?
(Guess: No. NSFetchRequest asks for one and only one entity)
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntities" inManagedObjectContext:[self context]];
[request setEntity:entity];
There is the request set up, calling:
NSMutableArray *mutableFetchResults = [[[[self context] executeFetchRequest:request error:&error] mutableCopy] autorelease];
Will return an array of all my MyEntities persistet by Core Data.
You can pass the request sortDescriptors or predicates to filter and sort the return values, but the value is always an array.
It is a bit tricky, but extremely useful.
精彩评论