在创建时有没有办法NSFetchRequest
指定要返回的实体数量。在下面的示例中,我只想要拥有最多镜头的前 3 个 Zombie 作品,我认为fetchBatchSize
可能会这样做,但它会返回 3 个批次,直到检索到所有 Zombie 作品。有谁知道你会怎么做?
- (void)setupFetchedResultsController {
// CREATE FETCH REQUEST
NSFetchRequest *fRequest = [[NSFetchRequest alloc] initWithEntityName:@"Production"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains %@", @"Zombie"];
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"shots" ascending:NO];
[fRequest setPredicate:predicate];
[fRequest setSortDescriptors:[NSArray arrayWithObject:descriptor]];
[fRequest setFetchBatchSize:3];
// FETCH RESULTS CONTROLLER
NSManagedObjectContext *moc = [[self managedDocument] managedObjectContext];
[self setFetchedResultsController:[[NSFetchedResultsController alloc] initWithFetchRequest:fRequest
managedObjectContext:moc
sectionNameKeyPath:nil
cacheName:nil]];
[[self fetchedResultsController] setDelegate:nil]; // NO UPDATES
}