2014-12-08 99 views
0

从我在网上找到的东西看起来好像这将是从多个值的核心数据中选择的方式。我想从machineName = 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]; 

回答

0

原来这是为了做到这一点,我没有插入到核心数据以正确的方式妥善

相关问题