2011-06-23 37 views
2

我有一个具有.localConcerts提取属性的艺术家对象(基本上是完整集合的一个子集,concerts集合),我可以在我的NSFetchedResultsController谓词中使用该属性吗?NSFetchedResultsController谓词中的提取属性

这里就是我想:

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Artist" inManagedObjectContext:context]; 
[request setEntity:entity]; 

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"[email protected] > 0"]; 
[request setPredicate:predicate]; 

fetchedResultsController = [[NSFetchedResultsController alloc] 
          initWithFetchRequest:request 
          managedObjectContext:context 
          sectionNameKeyPath:nil 
          cacheName:nil]; 

但我发现了:

'keypath localConcerts not found in entity <NSSQLEntity Artist id=1>' 

我缺少的东西,或只是不能使用内部谓词获取属性?

回答

6

显然NSPredicate只能使用数据库结构中的属性进行过滤(这很有意义)。在我的情况下,使用子查询的伎俩:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(shows, $show, $show.distance < %@)[email protected] > 0", [SWDataManager sharedManager].localFilterDistance]; 

我不知道我们能做到subqueries in NSPredicate,这是伟大的知道。积分转到@kyleve

相关问题