在NSFetchedResultsController的谓词中获取属性

sam*_*tte 3 iphone core-data predicates

我有一个带有.localConcertsfetched属性的Artist对象(基本上是完整.set的子concerts集),我可以在NSFetchedResultsController谓词中使用该属性吗?

这是我正在尝试的:

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

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

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"localConcerts.@count > 0"];
[request setPredicate:predicate];

fetchedResultsController = [[NSFetchedResultsController alloc]
                            initWithFetchRequest:request
                            managedObjectContext:context
                            sectionNameKeyPath:nil
                            cacheName:nil];
Run Code Online (Sandbox Code Playgroud)

但是我得到了:

'keypath localConcerts not found in entity <NSSQLEntity Artist id=1>'
Run Code Online (Sandbox Code Playgroud)

我错过了什么,或者只是不可能在谓词中使用获取的属性?

sam*_*tte 6

显然NSPredicate只能使用数据库结构中的属性进行过滤(这很有意义).在我的例子中,使用子查询做了诀窍:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(shows, $show, $show.distance < %@).@count > 0", [SWDataManager sharedManager].localFilterDistance];
Run Code Online (Sandbox Code Playgroud)

我不知道我们可以在NSPredicate中子查询,这很有用.积分转到@kyleve.