[英]Using Core Data, iCloud and CloudKit for syncing and backup and how it works together
I am in the early stages of creating an app where I would like to save, sync and backup data.我正处于创建应用程序的早期阶段,我想在其中保存、同步和备份数据。 The app will not store any files just data in a database.该应用程序不会将任何文件仅存储在数据库中。 It is going to be iOS 8 and up so I am able to use CloudKit.它将是 iOS 8 及更高版本,因此我可以使用 CloudKit。 I did some research and still not clear on how Core Data, iCloud and CloudKit work together.我做了一些研究,但仍然不清楚 Core Data、iCloud 和 CloudKit 如何协同工作。
As far as understand CloudKit is just a way of getting and retrieving data to/from the cloud.据了解,CloudKit 只是一种向/从云端获取和检索数据的方式。 Is CloudKit just a different way of syncing data with iCloud? CloudKit 只是一种与 iCloud 同步数据的不同方式吗?
My questions are:我的问题是:
If I do use CloudKit, do I still need to create local core data database?如果我使用 CloudKit,我还需要创建本地核心数据数据库吗?
If the data is only stored in the cloud will user be able to access it when iOS device is not connected to the internet.如果数据仅存储在云中,则用户可以在 iOS 设备未连接到互联网时访问它。 I read that CloudKit will have only limited caching.我读到 CloudKit 只有有限的缓存。
If someone can kind of break down what each technology does in the process of saving and syncing core data database offline and online.如果有人可以分解每种技术在离线和在线保存和同步核心数据数据库的过程中所做的事情。
My current understanding is:我目前的理解是:
Core Data is used to store data locally Core Data 用于在本地存储数据
iCloud syncs the data and stores in the cloud iCloud 同步数据并存储在云端
CloudKit gives the ability to store and manage data in the cloud?? CloudKit 提供了在云中存储和管理数据的能力?
I hope I provided enough info for this question not to get closed.我希望我提供了足够的信息来解决这个问题。
It's like this:就像这样:
If you wanted to use CloudKit with Core Data, you'd have to write your own custom code to translate between managed objects and CloudKit records.如果您想将 CloudKit 与 Core Data 一起使用,您必须编写自己的自定义代码来在托管对象和 CloudKit 记录之间进行转换。 It's not impossible, but it's more code to write.这并非不可能,但要编写更多代码。 It might be more reliable but it's too soon to say for sure.它可能更可靠,但现在下定论还为时过早。
I wrote a blog post describing CloudKit from the perspective of someone who's used Core Data and iCloud in the past.我写了一篇博文,从过去使用 Core Data 和 iCloud 的人的角度描述 CloudKit。
Update , June 2016: As of the most recent documentation for NSPersistentStoreCoordinator
, everything related to Core Data with iCloud is marked as deprecated. 2016 年 6 月更新:根据NSPersistentStoreCoordinator
最新文档,与 iCloud 核心数据相关的所有内容都被标记为已弃用。 As a result it should probably be avoided for new development.因此,新的开发可能应该避免使用它。
With iOS 13, Apple announced new features in Core Data to better work with CloudKit.在 iOS 13 中,Apple 宣布了 Core Data 中的新功能,以更好地与 CloudKit 配合使用。 The main addition is NSPersistentCloudKitContainer which basically manages syncing between Core Data and CloudKit for you.主要的新增功能是NSPersistentCloudKitContainer ,它基本上为您管理 Core Data 和 CloudKit 之间的同步。
You can learn more in the WWDC session Using Core Data with CloudKit .您可以在 WWDC 会议将 Core Data 与 CloudKit 结合使用来了解更多信息。
Apple also released a nice collection of docs for this very usage: Mirroring a Core Data store with CloudKit . Apple 还针对这种用法发布了一系列不错的文档: 使用 CloudKit 镜像核心数据存储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.