新的Core数据的iphone [英] New to Core Data for iphone

查看:110
本文介绍了新的Core数据的iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的iphone平台,并创建一个应用程序检索rss源和显示在UITableView。我已经得到这个工作完美(或者,更确切地说,我想要的方式)。我想是我将存储当前的feed项目在手机上,以便它将初始加载它存储的旧项目,当它有新的feed,然后解析新的feed并添加新的项目和刷新TableView。我将使用Core Data来存储旧的Feed项,因为这将是一个学习Core Data的好方法,它将是Core Data的合适使用。但是,我有一个困难的时间学习如何使用Core Data并将其与表/数组连接。



我已经googled并查看stackoverflow教程,但有但是找到任何解释它的方式,我真正理解。任何解释将核心数据添加到现有应用程序所需的总步骤将非常感谢。完整的细节不是必要的(但也是有用的)。我只是不是很有经验的SQL或数据存储这样的方式,我无法围绕如何Core Data的整个概念的工作原理以及它如何连接到一切。


$ b

解决方案

此外,为基于核心数据的应用程序存在Xcode模板;这些都是一个伟大的开始得到核心数据的地面。但是,它听起来像是要将Core Data集成到您现有的应用程序中,因此您需要...




  • 添加三个主要核心数据对象:受管对象上下文(MOC),受管对象模型(MOM)和持久存储协调器(PSC)。这些都需要在您希望Core Data可用的地方访问,因此无论是在您的应用程序代理中,还是在表格视图的控制器或数据源中都可用。

  • 在Xcode中创建MOM 。这将是一个类型为.xcdatamodel的文件,它是一个对象图,定义您在应用程序中需要的所有Core Data实体。

  • 使用NSFetchedResultsController(由Louis Gerbarg建议)

  • 在现有的RSS提取和解析例程中添加代码,以便在适当时将新的Core Data对象存储回商店。



一个好的方法是创建一个新的Core Data应用程序,您还可以查看Apple的精彩资源,例如核心数据编程指南和示例应用程序食谱地理位置 。 (可能需要开发人员注册。)



最后要注意的是,在大多数情况下,您需要添加的很多Core Data代码可以直接翻录从一个Xcode模板应用程序中,并粘贴到您的程序(这尤其适用于您需要的三个Core Data对象的访问器)。但请小心,不要使用你不明白的代码。


I am new to the iphone platform and am creating an app that retrievals a rss feed and displays it in a UITableView. I have gotten this working perfectly (or rather, the way I wanted). What I was thinking was I would store the current feed items on the phone so that it would initally load the old items it has stored while it got the new feed, then parse the new feed and add the new items and refresh the TableView. I was going to use Core Data to store it the old feed items because it would be a good way of learning Core Data and it would be an appropriate use of Core Data. However, I am having a difficult time learning how to use Core Data and connecting it with the Table/Array.

I have already googled and looked on stackoverflow for tutorials but have yet to find anything that explains it in a way I really understand. Any explanation of the overall steps that it takes to add Core Data to an existing app would be greatly appreciated. Full-blown detail are not necessary (but would also be useful). I'm just not very experienced with SQL or storing of data in such a manner and am having trouble wrapping my head around how the whole concept of Core Data works and how it connects to everything.

Also, any better method of doing what I'm trying to accomplish would also be appreciated.

解决方案

There exist Xcode templates for Core Data-based applications; these are a great start to getting Core Data off the ground. However, it sounds like you want to integrate Core Data into your existing app, so you'll need to...

  • Add three main Core Data objects: the managed object context (MOC), the managed object model (MOM), and the persistent store coordinator (PSC). These need to be accessible wherever you want Core Data available, so either in your app delegate or, more preferably, in the controller or data source for your table view.
  • Create a MOM in Xcode. This will be a file of type .xcdatamodel, and it's an object graph that defines all the Core Data entities you want in your app.
  • Use NSFetchedResultsController (as suggested by Louis Gerbarg) to get data out of Core Data and display it into your table view.
  • Add code in your existing RSS-fetching-and-parsing routines to store new Core Data objects back into the store, when appropriate.

A good way to start is just to create a new Core Data application and play around with it a bit; you can also look at Apple's fantastic resources on the subject, like the Core Data Programming Guide and the sample apps Recipes and Locations. (Developer registration may be required.)

One last thing to note is that for the most part, a lot of the Core Data code you need to add can be ripped straight out of one of the Xcode template apps and pasted into your program (this holds especially true for the accessors for the three Core Data objects you need). Be careful not to use code you don't understand, though.

这篇关于新的Core数据的iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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