我有一个(SQL)代码数据实体,其属性名为date
. 我构造一个谓词并获取请求,并声明一个数组来保存结果,如下所示
NSDate *firstDate = <date1>;
NSDate *lastDate = <date2>;
NSArray *dates = [NSArray arrayWithObjects: firstDate, lastDate, nil];
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:
@"date BETWEEN %@", dates];
NSFetchRequest * req = [NSFetchRequest fetchRequestWithEntityName:@"myEntity"];
NSArray * results;
以下作品
results = [managedObjectContext executeFetchRequest:req error:nil];
// gets all records
results = [results filteredArrayUsingPredicate:myPredicate];
// results now has the records I wanted
但以下不
req.predicate = myPredicate;
NSArray * results = [managedObjectContext executeFetchRequest:req error:nil];
这在控制台中
-[__NSTaggedDate constantValue]:无法识别的选择器发送到实例...
必须检索所有记录然后过滤它们似乎是错误的。为什么谓词不能与 fetch 请求一起使用?这是 SQLite 限制吗?我知道日期存储为NSTimeInterval
s (即双打),并在谓词中尝试了这些,但类似的问题。