gpt4 book ai didi

iphone - 在 NSFetchedResultsController 的谓词中获取属性

转载 作者:行者123 更新时间:2023-12-03 19:36:47 28 4
gpt4 key购买 nike

我有一个带有 .localConcerts 获取属性的 Artist 对象(基本上是完整 .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];

但我得到:

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

我是否遗漏了任何内容,或者只是无法在谓词内使用获取的属性?

最佳答案

显然NSPredicate只能使用数据库结构中的属性进行过滤(这是有道理的)。就我而言,使用子查询就达到了目的:

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

我不知道我们能做什么subqueries in NSPredicate ,很高兴知道。积分转到 @kyleve .

关于iphone - 在 NSFetchedResultsController 的谓词中获取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6449615/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com