有下面三个类型获取,需要添加一个AND语句过滤结果,其中mark是使用状态。
1.
NSMutableArray *questionNumberArray=[[NSMutableArray alloc] init];
// Fetch questions
NSManagedObjectContext *context = self.document.managedObjectContext;
NSFetchRequest *fetchRequest =
[[NSFetchRequest alloc] initWithEntityName:@"Questions"];
//building the predicate with selected category
NSMutableArray *parr = [NSMutableArray array];
if ([cat0str length]){
[parr addObject:[NSPredicate predicateWithFormat:@"question.category CONTAINS[c] %@",cat0str]];
}
if ([cat1str length]){
[parr addObject:[NSPredicate predicateWithFormat:@"question.category CONTAINS[c] %@",cat1str]];
}
if ([cat2str length]){
[parr addObject:[NSPredicate predicateWithFormat:@"question.category CONTAINS[c] %@",cat2str]];
}
NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:parr];
[fetchRequest setPredicate:compoundPredicate];
2.
NSPredicate *markPredicate =[NSPredicate predicateWithFormat:@"question.mark == 1"];
}
想要实现的是:
NSPredicate *finalPredicate = [compoundPredicate && markPredicate];
[fetchRequest setPredicate:finalPredicate];