Cocoa 核心数据获取中的谓词不';t返回与数组上相同谓词相同的结果

Cocoa 核心数据获取中的谓词不';t返回与数组上相同谓词相同的结果,cocoa,core-data,nspredicate,nsfetchrequest,Cocoa,Core Data,Nspredicate,Nsfetchrequest,在下面的示例中,为什么两个属性数组没有相同的元素?第一个数组为空,第二个数组包含1个元素,但它们使用相同的谓词 NSError *error; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"publication.store.storageMode != 0 && publication.store.complete == NO && publication.download == NIL

在下面的示例中,为什么两个
属性
数组没有相同的元素?第一个数组为空,第二个数组包含1个元素,但它们使用相同的谓词

NSError *error;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"publication.store.storageMode != 0 && publication.store.complete == NO && publication.download == NIL"];

NSFetchRequest *request1 = [NSFetchRequest fetchRequestWithEntityName:@"Property"];
request1.predicate = predicate;
NSArray *properties1 = [self executeFetchRequest:request1 error:&error];

NSFetchRequest *request2 = [NSFetchRequest fetchRequestWithEntityName:@"Property"];
NSArray *allProperties = [self executeFetchRequest:request2 error:&error];
NSArray *properties2 = [allProperties filteredArrayUsingPredicate:predicate];
  • 属性1
    有0个元素
  • allProperties
    有12个元素
  • 属性2
    有1个元素

我不明白为什么第一个请求没有返回我在第二个方法中得到的一个元素。难道它们不应该是等价的吗?

这可能不是一个答案,我不知道如何在注释中写出suych长文本。我不太确定您不能在CoreData谓词中直接使用BOOL进行获取

因此,出于测试目的,我将尝试使用两个不同的谓词:

NSPredicate *predicateArray = [NSPredicate predicateWithFormat:@"publication.store.storageMode != 0 && publication.store.complete == NO && publication.download == NIL"];

NSPredicate *predicateCoreData = [NSPredicate predicateWithFormat:@"publication.store.storageMode != 0 && publication.store.complete == %@ && publication.download == NIL",[NSNumber numberWithBool:myBool]];

另外,我将用NIL替换NIL。

删除这一行,然后尝试request1.predicate=predicate;什么线路?我已经做了
request1.predicate=predicate。第一段代码返回0结果;只有对于request1,您才这样设置。所以我要求删除这一行request1.predicate=predicate;这就是重点。请求1在fetch请求中使用谓词,不返回任何结果。请求2不使用谓词,因此它返回一个包含所有
Property
对象的数组。如果对数组使用相同的谓词,则得到1个结果,而第一种情况为0。这就是我想解释的。可能是因为核心数据使用了底层SQLite请求……您在过滤数组中获得的属性是否具有零发布或存储?