gpt4 book ai didi

ios - 带有谓词的CoreData fetchRequest错误地跳过NULL值

转载 作者:行者123 更新时间:2023-12-01 18:44:35 26 4
gpt4 key购买 nike

我在CoreData中存储了看起来像这样的对象:

id  name  type1   cat   aaa2   dog   bbb3   ape   NULL

I'm fetching these objects based on the "type" property like this:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:self.entityName];

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"type != %@", @"aaa"];
fetchRequest.fetchBatchSize = 100;
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"type" ascending:YES]];

NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"section" cacheName:nil];
fetchedResultsController.delegate = self;

NSError *error = nil;
[fetchedResultsController performFetch:&error];

因此,我只是尝试获取类型与“aaa”不同的所有对象。

提取请求意外地不仅删除了谓词中指定的具有“aaa”类型的对象,而且还忽略了未设置类型(空)的对象,从而导致以下结果:
id  name  type2   bar   bbb

Instead of what I'd expect:

id  name  type2   dog   bbb3   ape   NULL

The same problem happens when I use predicate format: NOT (type IN {"aaa", "bbb"}). Which is the actual way I'll be needing this. This predicate results in no records getting fetched.

I fail to see why this could happen, because if I don't specify a predicate all objects get fetched properly. Objects with NULL types do get fetched correctly if I'd change the predicate to:

[NSPredicate predicateWithFormat:@"type = null"];

请注意;以上所有内容仅说明了问题的根源。我的实际代码更加复杂,仅使用谓词格式: type != "aaa" OR type = null是我希望避免的东西。

任何帮助,不胜感激!

最佳答案

关于ios - 带有谓词的CoreData fetchRequest错误地跳过NULL值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37474058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com