如何从多个过滤器中选择核心数据?

时间:2014-12-08 02:45:36

标签: ios objective-c core-data

从我在网上找到的内容看来,这似乎是从多个值的核心数据中进行选择的方式。我想从机器名称= var1或machineName = var2的练习中获取所有内容...无论出于何种原因,在我通过executeFetchRequest选择器调试并且equiptmentData为空之后没有返回任何内容。我也没有任何错误。任何帮助或建议都非常感谢,并提前感谢。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"Exercises" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];

NSMutableArray *predicates = [[NSMutableArray alloc] init];

for(int i = 0; i < [checked count]; i++)
{
    if([[checked objectAtIndex:i] boolValue] == YES)
    {
         NSPredicate *predicate = [NSPredicate predicateWithFormat:@"machineName == %@", itemArray[i]];
        [predicates addObject: predicate];
    }
}
NSArray *predicatesArray = [[NSArray alloc] initWithArray: predicates];
NSPredicate * compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates: predicatesArray];

fetchRequest.predicate = compoundPredicate;

NSError *error = nil;
NSArray *equiptmentData = [managedObjectContext executeFetchRequest:fetchRequest error: &error];

1 个答案:

答案 0 :(得分:0)

原来这是执行此操作的正确方法我没有正确插入核心数据