我有2个NSManagedObjects实体:VNSource< * - > VNDataChart(使用SQLite后端iOS)。 在一些用户的活动之后,我有NSArray和选定的图表 - listChartToDownload(包含VNDataChart对象)。
我想根据listChartToDownload中的对象构建谓词来过滤VNSource中的所有记录。 通过迭代listChartToDownload中每个对象的获取请求,我成功获得了VNSource对象的结果数组。但在我看来,你有更有效的方法。
我尝试在下面执行此代码,但结果为false - 在arrayRequest中只有一个VNSource对象(应该> 30)。
你能解释我的错误吗?
NSFetchRequest *localRequest = [[NSFetchRequest alloc] init];
localRequest.entity = [NSEntityDescription entityForName:@"VNSource" inManagedObjectContext:context];
localRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"resolution" ascending:YES]];
localRequest.predicate = [NSPredicate predicateWithFormat:@"whichChart = %@" argumentArray: listChartToDownload];
localRequest.fetchBatchSize = 100;
arrayRequest = [context executeFetchRequest:localRequest error:&error1];
[localRequest release];
答案 0 :(得分:3)
根据我对您的问题的理解,您应该使用whichChart IN %@
代替whichChart = %@
。
而且,您应该只是这样做:
[NSPredicate predicateWithFormat:@"whichChart IN %@", listChartToDownload]