iphone 的 Core Data 新手 [英] New to Core Data for iphone

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

问题描述

我是 iphone 平台的新手,正在创建一个应用程序来检索 rss 提要并将其显示在 UITableView 中.我已经完美地完成了这项工作(或者更确切地说,是我想要的方式).我在想的是,我会将当前的提要项目存储在手机上,以便它在获取新提要时首先加载它存储的旧项目,然后解析新提要并添加新项目并刷新 TableView.我打算使用 Core Data 来存储旧的提要项目,因为这将是学习 Core Data 的好方法,并且会是 Core Data 的适当使用.但是,我很难学习如何使用 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.

我已经在 google 上搜索并查看了 stackoverflow 的教程,但还没有找到任何以我真正理解的方式解释它的内容.将核心数据添加到现有应用程序所需的整体步骤的任何解释将不胜感激.完整的细节不是必需的(但也很有用).我只是不太熟悉 SQL 或以这种方式存储数据,并且无法理解 Core Data 的整个概念是如何工作的以及它如何连接到所有内容.

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.

推荐答案

存在适用于基于 Core Data 的应用程序的 Xcode 模板;这些是让 Core Data 起步的良好开端.但是,听起来您想将 Core Data 集成到您现有的应用程序中,因此您需要...

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...

  • 添加三个主要的核心数据对象:托管对象上下文 (MOC)、托管对象模型 (MOM) 和持久存储协调器 (PSC).这些需要在您希望 Core Data 可用的任何地方都可以访问,因此无论是在您的应用委托中,还是在您的表视图的控制器或数据源中,更佳.
  • 在 Xcode 中创建一个 MOM.这将是一个 .xcdatamodel 类型的文件,它是一个对象图,用于定义您需要在应用中使用的所有核心数据实体.
  • 使用 NSFetchedResultsController(按照 Louis Gerbarg 的建议)从 Core Data 中获取数据并将其显示到您的表视图中.
  • 在您现有的 RSS 获取和解析例程中添加代码,以在适当的时候将新的 Core Data 对象存储回商店.

一个好的开始方法是创建一个新的 Core Data 应用程序并稍微尝试一下;您还可以查看 Apple 关于该主题的出色资源,例如 核心数据编程指南 和示例应用Recipes位置.(可能需要开发者注册.)

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.)

最后要注意的一点是,在大多数情况下,您需要添加的许多 Core Data 代码可以直接从 Xcode 模板应用程序之一中提取并粘贴到您的程序中(这对于您需要的三个 Core Data 对象的访问器).不过,请注意不要使用您不理解的代码.

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.

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

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