具有NSPredicate和OR条件的CoreData

时间:2014-10-21 18:56:59

标签: ios core-data nspredicate

我对 NSPredicate 有疑问。

我使用此谓词来获取status=="Compare"

的所有结果
NSFetchRequest *request = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription @"MyEntity"
                                                  inManagedObjectContext:context];
        [request setEntity:entity];

        NSPredicate *predicate =
        [NSPredicate predicateWithFormat:@"status == %@",@"Created"];
        [request setPredicate:predicate];

但是现在我想把所有结果都归结为" Created" " Readed"。 我怎么改变我的谓词?

2 个答案:

答案 0 :(得分:0)

这会起作用吗?

[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
  return [[evaluatedObject status] isEqualToString:@"Created"] || [[evaluatedObject status] isEqualToString:@"Readed"];
}];

答案 1 :(得分:0)

尝试

[NSPredicate predicateWithFormat:@"status IN %@",@[@"Created", @"Readed"]];