更新NSFetchedResultsController的结果,而不进行新的提取 [英] Update results of NSFetchedResultsController without a new fetch

查看:157
本文介绍了更新NSFetchedResultsController的结果,而不进行新的提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个应用程序,它保存在外部MySQL服务器中的数据,但缓存在本地使用Core Data更好的响应时间。基本上,我想做的是:


  1. 从Core Data获取数据(SQLite数据存储,使用NSFetchedResultsController)

  2. 在后台从MySQL服务器抓取新项目

  3. 使用新的数据集(包括新项目和旧项目)刷新当前表视图

我所有的工作除了最后一步。我不能弄清楚如何使NSFetchedResultsController更新其数据集。到目前为止,我已经尝试直接添加项目到其NSManagedObjectContext:

  [NSEntityDescription insertNewObjectForEntityForName:@Entity
我也试过了苹果在他们的CoreDataBooks例子中做的,并使用单独的添加托管对象上下文和对 mergeChangesFromContextDidSaveNotification:的调用。这似乎没有更改NSManagedObject *当前在我获取的结果控制器的管理对象上下文中的集合。



我如何去更新NSFetchedResultsController当前管理的对象集?

解决方案

我发现我的问题不是对象不更新,而是NSFetchedResultsController实例不是



从获取的结果控制器更新托管对象上下文确实更新控制器的结果对象集。


I'm working on an application that holds its data in an external MySQL server, but caches it locally using Core Data for better response times. Basically, what I'd like to do is this:

  1. Fetch data from Core Data (SQLite data store, using NSFetchedResultsController) and display it
  2. Grab new items from the MySQL server in the background
  3. Refresh the current table view with the new set of data (both new and old items)

I have all this working except the last step. I can't quite figure out how to make an NSFetchedResultsController update its set of data. So far, I've tried adding items directly to its NSManagedObjectContext:

[NSEntityDescription insertNewObjectForEntityForName:@"Entity"
                              inManagedObjectContext:[fetchedResultsController
                                                      managedObjectContext]];

I've also tried what Apple does in their CoreDataBooks example, and used a separate "adding" managed object context and a call to mergeChangesFromContextDidSaveNotification:. Neither seems to change the set of NSManagedObject*s currently in my fetched result controller's managed object context.

How would I go about updating the set of objects an NSFetchedResultsController currently manages?

解决方案

I found out my issue was not that the objects weren't updating, but that the NSFetchedResultsController instance I had wasn't updating its section index titles properly, and I therefore couldn't see the results in my UITableView.

Updating a managed object context from a fetched results controller does update the controller's result object set.

这篇关于更新NSFetchedResultsController的结果,而不进行新的提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆