理解核心数据 Swift

Posted

技术标签:

【中文标题】理解核心数据 Swift【英文标题】:Understanding Core Data Swift 【发布时间】:2015-09-03 12:13:01 【问题描述】:

我是 ios 开发的超级初学者,我有一个关于 Core Data 的问题。我知道这似乎是一个愚蠢的问题,但由于描述它所涉及的所有行话,我很难理解它是什么。例如,https://en.wikipedia.org/wiki/Core_Data 表示:

It allows data organised by the relational entity–attribute model to be serialised into XML, binary, or SQLite stores. The data can be manipulated using higher level objects representing entities and their relationships. Core Data manages the serialised version, providing object lifecycle and object graph management, including persistence. Core Data interfaces directly with SQLite, insulating the developer from the underlying SQL.

另一个链接:http://shrikar.com/core-data-swift-tutorial/ 状态:

Core Data framework provides a simple way of maintaining the life cycle of the objects and object graph management including persistence.

我在谷歌上搜索,“什么是核心数据 swift”,大多数链接的语言和行话都相似。因此,真的很难理解它的作用。您能否用外行的方式解释一下核心数据实际上是什么?

附注我想我基本上了解核心数据的作用。它只是保存数据以便我以后可以使用它?但是这种理解足以让我继续使用核心数据吗?还是我需要更深入的了解?

【问题讨论】:

【参考方案1】:

CoreData 是您保存数据以供以后使用的一种方式。但是,它可以更强大。这是一个Object-Graph,您可以创建relationshipschain 多个对象一起形成这种关系。

在非常简单的应用程序中,Core Data 可以用作Dictionary,在关闭应用程序时不会丢失数据。但是,它可以更多。

CoreData 的一个应用程序超越了一种简单的数据存储方式,它可以保存多个“Person”对象并创建许多社交应用程序使用的关注者/关注者模型。也许您想查询您保存的数据模型:“找到所有关注此人的用户”。在 Core Data 中建立的关系将允许您在保存的数据库中进行此类查询。

【讨论】:

以上是关于理解核心数据 Swift的主要内容,如果未能解决你的问题,请参考以下文章

Swift:多对关系和 mutableOrderedSetValueForKey 的核心数据问题

在 Swift 3(核心数据)中引用实体属性

核心数据检查是不是已经保存,Swift

swift中的核心数据

Swift 核心数据问题

Swift 核心数据 FetchRequest NSData 到 UIIMage