【发布时间】:2013-01-25 17:50:56
【问题描述】:
我正在使用最新的 SDK 和 Xcode 4.5.2 开发一个 iOS 应用程序。部署目标是 4.3。
我正在使用 Core Data 来访问这个实体:
我想过滤商店,但不知道怎么做(这是我的第一个 Core Data 项目)。
我知道我必须将NSFetchRequest 与NSPredicate 或NSExpression 一起使用。
我写这个 if 语句是为了告诉你我想要做什么:
if ((shop.acceptRate >= filterCriteria.acceptRate) &&
(shop.categoryId == filterCriteria.shopCategoryId) &&
([shop.productsId indexOfObject:filterCriteria.productCategoryId] != NSNotFound) &&
([latestLocation distanceFromLocation:shop.shopLocation] <= (filterCriteria.distance * 1000)))
{
[ ... ]
}
如何将NSFetchRequest 与NSPredicate 或NSExpression 一起使用?
我认为是这样的:
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"acceptRate >= %@ AND categoryId = %@", filterCriteria.acceptRate, filterCriteria.shopCategoryId];
但我不知道如何在NSPredicate 上写产品关系。
【问题讨论】:
标签: ios core-data nsfetchrequest