【问题标题】:Add a Relationship filter to NSPredicate将关系过滤器添加到 NSPredicate
【发布时间】:2013-01-25 17:50:56
【问题描述】:

我正在使用最新的 SDK 和 Xcode 4.5.2 开发一个 iOS 应用程序。部署目标是 4.3。

我正在使用 Core Data 来访问这个实体:

我想过滤商店,但不知道怎么做(这是我的第一个 Core Data 项目)。

我知道我必须将NSFetchRequestNSPredicateNSExpression 一起使用。

我写这个 if 语句是为了告诉你我想要做什么:

if ((shop.acceptRate >= filterCriteria.acceptRate) &&
    (shop.categoryId == filterCriteria.shopCategoryId) &&
    ([shop.productsId indexOfObject:filterCriteria.productCategoryId] != NSNotFound) &&
    ([latestLocation distanceFromLocation:shop.shopLocation] <= (filterCriteria.distance * 1000)))
{
    [ ... ]
}

如何将NSFetchRequestNSPredicateNSExpression 一起使用?

我认为是这样的:

NSPredicate* predicate =
   [NSPredicate predicateWithFormat:@"acceptRate >= %@ AND categoryId = %@", filterCriteria.acceptRate, filterCriteria.shopCategoryId];

但我不知道如何在NSPredicate 上写产品关系。

【问题讨论】:

    标签: ios core-data nsfetchrequest


    【解决方案1】:

    根据您提供的信息,这样的事情应该可以工作:

    NSPredicate* predicate = [NSPredicate predicateWithFormat:@"acceptRate >= %@ AND categoryId = %@ AND %@ IN products", filterCriteria.acceptRate, filterCriteria.shopCategoryId, filterCriteria.product];
    

    其中filterCriteria.productProduct 类型的NSManagedObject 实例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 2012-01-22
      相关资源
      最近更新 更多