iOS的核心数据结构技巧希望

iOS的核心数据结构技巧希望

本文介绍了iOS的核心数据结构技巧希望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想获得的最好办法建筑师几个指针我的第一个核心数据的应用程序,主要对象和互动,我会要求。

I just want to get a few pointers on the best way to architect my first Core Data app, and the main objects and interactions I will require.

中的数据被远程存储,我需要通过HTTP访问它,它会以JSON格式响应。我想这个缓存使用核心数据设备。每天都会有服务器上的新数据,所以我需要相应访问这一点,并更新模型。

The data is stored remotely and I will need to access it via HTTP and it will respond in JSON format. I want to cache this on the device using Core Data. Each day there will be new data on the server, so I need to access this and update the Model accordingly.

有没有我可以用它来帮助我的任何SDK类,还是我要手卷呢?

Are there any SDK classes I can use to help me with this, or am I going to hand roll it?

我想我在寻找一个模式控制器,我打电话来获取数据,它将返回核心数据缓存的数据,也许让一个后台调用Web服务来获取最新数据太多,然后通知认为,有新的数据。当我从JSON格式的Web服务的数据 - 我需要将此映射到一个ManagedObjects添加到我的核心数据上下文

I guess I'm looking at a Model Controller that I call to get the data, it will return the core data cached data and maybe make a background call to the web service to get latest data too and then notify the view that there is new data. When I get the data from web service in JSON format - i will need to map this to ManagedObjects an add to my core data context.

推荐答案

感谢dtuckernet,这里是什么我没做 - 收集来自许多来源,我相信这是最好的解决办法的信息。任何人随意批评(建设性)......

Thanks dtuckernet, here is what I did do - gathering info from lots of sources, which I believe is the best solution. Anyone feel free to criticise (constructively)....


  1. 我有我的CoreDataStack.h核心数据堆栈(单) - 不完全是必要的,但unclutters我的应用程序委托类

  2. 我有一个基地CoreDataBackedTableViewController:的UITableViewController
  3. 我的每一个表视图屏幕扩展CoreDataBackedTableViewController并有伊娃到ModelController类。

  4. 一个例子ModelController类有一个 - (NSFetchedResultsController *)的getData方法,构造NSFetchedResultsController(也养了裁判的话),并返回到视图控制器也将其存储在CoreDataBackedTableViewController(侦听更新和编辑的数据)。具有ModelController类允许我概括了我的数据访问可能有2个不同的视图控制器使用它(iPhone和iPad也许)

  5. 在的getData - 我做异步到我的后端web服务的调用。使用委托回调

  6. 后端使用SBJSON解析和NSHttpConnection和手卷HTTPService类。

  7. 当数据后端的回报,它调用哪些更新核心数据上ModelController委托 - 我fetchedResultsController知道这一点,并自动更新我的界面!如何冷静是该位 - 不是有很多涉及我的部分努力。我要做我是否已经下载的数据之前,还是不以避免重复一些检测。

  8. 准备滚了这一点,以我的应用程序的其余部分....

如果有人想在任何步骤任何解释,只是让我知道。

If anyone wants any clarification on any of the steps, just let me know.

这篇关于iOS的核心数据结构技巧希望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:09