是否有可能拥有多个核心数据“数据库"?在一个 iOS 应用上? [英] Is it possible to have multiple core data "databases" on one iOS app?
问题描述
我想编写一个大量使用核心数据的管理"游戏.游戏需要用户/系统无法更改的预设、预定义数据集;它用于为游戏提供数据种子,并且是只读的.
I'm wanting to write a "management" game that utilizes Core data heavily. The game requires a pre-set, pre-defined dataset that cannot be changed by the user/system; it is used to seed the game with data and is meant to be read-only.
我能举的最好的例子是足球管理游戏,但它可以是任何东西.在一些足球管理模拟游戏中,它们为您提供场景和预设数据集.
The best example I can give is a football management game, but it could be anything. In some football management sims they give you scenarios and pre-set datasets.
随着用户进行游戏,他们可以保存/加载保存到核心数据中的进度.
As the user proceeds through the game they can save/load their progress which is saved to the core data.
除此之外,用户还可以接收预定义数据的更新或购买场景数据包;保存到他们的设备中.
In addition to this, the user can receive updates to the pre-defined data or can purchase scenarios packs of data; which is saved to their device.
因此,应用程序可以深入研究和使用多个核心数据数据库"(是的,我知道核心数据并不是严格意义上的数据库)或存储桶".
So, there could be multiple "core data databases" (yes, I know core data isn't strictly a database) or "buckets" which the app can dive into and use.
数据的架构不会改变.
所以我们有:
- 预定义数据(默认数据),仅用于为游戏做种.
- 用户当前的存档游戏.
- 用户已从 Internet 下载了一个场景.
- 问题:当用户在场景"中保存游戏时会发生什么.
- 问题:如何在核心数据中跟踪所有场景和所有用户保存的游戏?
这听起来像是在给定时间有多个数据库.显然应该限制一个用户可以制作多少个存档游戏.
This sounds like multiple databases at a given time. Obviousily one should restrict how many save games a user can make.
对此的替代解决方案是用户的设备以 JSON 或 XML 格式导出数据的备份副本,这用作保存数据",我也可以将此策略用于场景.显然需要某种加密来防止人们简单地通过 XML 更改游戏中的统计数据.
An alternative solution to this is that the user's device exports a back-up copy of the data in JSON or XML and this serves as the "save data" and I could use this strategy for scenarios too. Obviousily some kind of encryption would be needed to prevent people simply changing stats in the game via the XML.
但我从一开始就想知道在 iOS 设备上使用核心数据的最佳方式是什么来处理 1 个以上的核心数据数据库"?
But I'm wondering from the outset what would be the best way to use Core data for iOS devices handle more than 1 core data "database"?
感谢您的时间
推荐答案
如果数据模型相同,你可以设置你的 MOC 以便它同时使用持久化存储......一个是只读的,另一个是即读/写.
If the data models are the same, you can just setup your MOC so that it uses both persistent stores... one which is read-only and the other that is read/write.
或者,您可以为每个商店使用单独的 MOC.
Or, you could use separate MOC for each store.
因此,您想如何使用它是您唯一的决定因素,因为您几乎可以拥有 MOC/PSC 的任何组合.
So, how you want to use it is your only decision factor, since you can have almost any combination of MOC/PSC.
查看文档此处了解更多信息.
Look at the documentation here for more information.
编辑:
此问题给出的链接已失效,其他人建议 此链接 在另一个已删除的答案中.
The link given with this question is dead, someone else suggested this link in another deleted answer.
这篇关于是否有可能拥有多个核心数据“数据库"?在一个 iOS 应用上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!