使用iPhone应用程序的核心数据有什么价值吗? [英] Is there any value in using core data for iPhone apps?

查看:127
本文介绍了使用iPhone应用程序的核心数据有什么价值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们能给我一些例子,说明他们为什么在应用程序中使用coreData?

Can people give me examples of why they would use coreData in an application?

我问这是因为大多数应用程序只是一个中央服务器的客户端,其中某种API可以为您提供所需的信息。

I ask this because most apps are just clients to a central server where an API of some sort gives you the information you need.

在我的例子中,我为一个web应用程序编写一个时间表应用程序,它有一个API,我辩论如果在复制我的数据结构中有任何价值服务器在核心数据(Sqlite)

In my case I'm writing a timesheet application for a web app which has an API and I'm debating if there is any value in replicating the data structure on my server in core data(Sqlite)

例如

项目有许多时间表
雇员有许多时间表

Project has many timesheets employee has many timesheets

在我看来,我可以在每次调用项目列表或现有时间表时连接到API。

It seems to me that I can just connect to the API on every call for lists of projects or existing timesheets for example.

我意识到某种离线模式可以在本地存储在核心数据,但这会导致更多的问题,因为你现在有一个很大的问题,同步数据回到web服务器,当你再次获得连接..为时间表选择的项目不再存在。

I realize for some kind of offline mode you could store locally in core data but this creates way more problems because you now have a big problem with syncing that data back to the web server when you get connection again.. e.g. the project selected for a timesheet no longer exists.

任何有经验的开发人员都可以了解核心数据是最佳实践方法的经验吗?

Can any experienced developer shed some light on there experiences on when core data is best practice approach?

我意识到存储本地持久性有价值,但用户默认值的关键值似乎涵盖了我可以想到的大多数应用程序。

I realise of course there is value in storing local persistance but the key value of user defaults seems to cover most applications I can think of.

推荐答案

您不应该将CoreData简单地视为SQLite数据库。它不是JUST一个SQLite数据库。当然,SQLite是一个选项,但也有其他选项,如内存中,和iOS5,一整套自定义数据存储。 CoreData最大的好处是持久性,显然。但是即使你使用内存中的数据存储,你也可以得到一个非常好的结构化对象图的好处,所有关于拉取信息或将信息放入数据存储的繁重工作都由CoreData处理你,而不必一定需要关心什么是支持数据存储。当然,今天你不太在意持久性,所以你可以使用内存中的数据存储。如果明天,一个月或一年,你决定添加一个真正受益于持久性的功能会发生什么?使用CoreData,您只需更改或添加持久性数据存储,并且所有方法都可以保持不变。与如果你试图直接访问SQLite或其他数据存储相比,这种添加的开销是最小的。 IMHO,这是最大的好处:抽象。而且,本质上,抽象是OOP背后最强大的事情之一。授予,构建仅用于内存存储的数据模型可能对您的应用程序有点过度,这取决于应用程序的涉及程度。但是,作为一个侧面的注释,你可能想要考虑什么是更快:从你的web服务请求信息每次你想执行一些操作,或请求一次信息,将其存储在内存中,并对该存储的值进行操作会议的其余部分。

You shouldn't think of CoreData simply as an SQLite database. It's not JUST an SQLite database. Sure, SQLite is an option, but there are other options as well, such as in-memory and, as of iOS5, a whole slew of custom data stores. The biggest benefit with CoreData is persistence, obviously. But even if you are using an in-memory data store, you get the benefits of a very well structured object graph, and all of the heavy lifting with regards to pulling information out of or putting information into the data store is handled by CoreData for you, without you necessarily needing to concern yourself with what is backing that data store. Sure, today you don't care too much about persistence, so you could use an in-memory data store. What happens if tomorrow, or in a month, or a year, you decide to add a feature that would really benefit from persistence? With CoreData, you simply change or add a persistent data store, and all of your methods to get information out or in remain unchanged. The overhead for that sort of addition is minimal in comparison to if you were trying to access SQLite or some other data store directly. IMHO, that's the biggest benefit: abstraction. And, in essence, abstraction is one of the most powerful things behind OOP. Granted, building the Data Model just for in-memory storage could be overkill for your app, depending on how involved the app is. But, just as a side note, you may want to consider what is faster: Requesting information from your web service every time you want to perform some action, or requesting the information once, storing it in memory, and acting on that stored value for the remainder of the session. An in-memory data store wouldn't persistent beyond that particular session.

此外,使用CoreData,您还可以获得许多其他重要功能,例如保存,提取和取消操作,重做。

Additionally, with CoreData you get a lot of other great features like saving, fetching, and undo-redo.

这篇关于使用iPhone应用程序的核心数据有什么价值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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