【问题标题】:Fetched Properties inside NSFetchedResultsController's predicate在 NSFetchedResultsController 的谓词中获取的属性
【发布时间】:2011-06-23 05:12:22
【问题描述】:

我有一个带有 .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>'

是我遗漏了什么,还是无法在谓词中使用获取的属性?

【问题讨论】:

    标签: iphone core-data predicates


    【解决方案1】:

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

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

    我不知道我们能做到subqueries in NSPredicate,很高兴知道。致谢@kyleve

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多