iphone 核心数据 - 过滤 NSFetchedResultController?

发布于 2024-09-28 09:51:56 字数 577 浏览 2 评论 0原文

我得到了一个由其他程序员编写的框架来访问核心数据。 在这种情况下,我收到一个预加载的 NSFetchedResultController,我需要对其进行过滤,以显示其部分数据。

这是我尝试过的:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];

我收到一条错误消息,指出无法设置对象,要么缺少 setter 方法,要么对象是只读的。

那么,过滤已加载的 NSFetchResultController 的最佳方法是什么,而不必将过滤后的数据存储到另一个数组中?

I was given a framework written by other programmers to access the core data.
In this situation i receive a pre-loaded NSFetchedResultController which I need to filter, to display a part of it's data.

Here is what I tried:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];

And i get an error saying that object cannot be set, either setter method is missing, or object is read-only.

So whats the best way to filter an NSFetchResultController which is already loaded, without having to store the filtered data into another array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-10-05 09:51:56

fetchedObjects 是只读的。您无法手动设置它。

您需要做的是使用 myResultController 执行新的获取。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
//myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];
[myResultController performFetch:nil];

fetchedObjects is readonly. You cannot set it manualy.

What you need to do is to perform a new fetch with your myResultController.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
//myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];
[myResultController performFetch:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文