核心数据与SQLite [英] Core Data vs SQLite

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

问题描述

我正在编写一个琐事应用程序,其中将包含数百套问题。

I am writing a trivia app in which there will be hundreds of sets of questions.

该应用程序将预先加载一些测验,但随后需要下载进一步的测验,一旦下载,这些测验将存储在应用程序中,以便用户可以离线播放。

The app will come pre loaded with some quizzes however they would then need to download further quizzes which once downloaded will be stored within the app so that users can play them offline.

在这种特定情况下,我最好使用核心数据或SQLite。

In this specific instance would I be better using core data or SQLite.

谢谢。

推荐答案

在这里您需要认识到的是CoreData 不是数据库。

The thing you have to realise here is that CoreData is not a DataBase.

这是应用程序中的对象持久层。默认情况下,它恰好由SQLite数据库支持,但这无关紧要。

It is an object persistence layer in your app. It happens to be backed by a SQLite DB by default but that's largely irrelevant.

我编写的应用程序带有一个CoreData存储,该存储包含大约100,000个实体和数百万个

I have written apps with a CoreData store that contains in the region of 100,000 entities and millions of relationships between them.

CoreData无法处理复杂数据的说法不正确。

The argument that CoreData cannot handle complex data is not correct.

诀窍在于设计对象模型就像在代码中定义对象模型一样。

The trick is to design your Object Model exactly like you would define you object model in code.

您不需要外键或联接表(这些都由Core Data为您处理) )。

You don't need foreign keys or join tables (these are all handled for you by Core Data).

如果您(例如)在学生之间存在多对多关系,则只需在它们之间创建一个关系并将其定义为两端的许多关系。核心数据将通过创建联接表和类似的东西来为您处理数据。您不必担心。

If you have (for instance) a many-to-many relationship between Class and Student then just create a relationship between them and define it as a Many relationship on each end. Core Data will handle the data for you by creating the join tables and stuff like that. You don't need to worry about that.

要预加载数据,您也可以这样做。这需要一些工作,但是您可以捆绑由CoreData生成的预加载数据库,并在初次启动时将其解包。

For preloading the data you can also do this. It takes a bit of work but you can bundle a preloaded DB generated by CoreData and unwrap it at initial launch.

使用哪个主要取决于意见(因此不是对于StackOverflow来说不是一个很好的问题)。有一些很棒的有关Ray Wenderlich网站上的核心数据的教程

Which to use comes largely down to opinion (and so isn't a very good question for StackOverflow). There are some excellent tutorials on Core Data on the Ray Wenderlich site.

如果您从未读过,那么值得一读以前使用过CoreData。

Worth reading through if you've never used CoreData before.

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

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