NSFetchRequest
我的问题:使用 Core Data重复使用多个不同的 fetch 有什么不好的吗?
示例代码:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *logEntity = [NSEntityDescription entityForName:@"LogEntry" inManagedObjectContext:context];
[request setEntity:logEntity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dateTimeAction" ascending:NO]; // ascending NO = start with latest date
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status == %@",@"op tijd"];
[request setPredicate:predicate];
[request setFetchLimit:50];
NSError *error = nil;
NSInteger onTimeCount = [context countForFetchRequest:request error:&error];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"status == %@",@"uitgesteld"];
[request setPredicate:predicate1];
[request setFetchLimit:50];
NSInteger postponedCount = [context countForFetchRequest:request error:&error];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"status == %@",@"gemist"];
[request setPredicate:predicate2];
[request setFetchLimit:50];
NSInteger missedCount = [context countForFetchRequest:request error:&error];