可以具有多个核心数据“数据库”在一个iOS应用程序? [英] Is it possible to have multiple core data "databases" on one iOS app?

查看:197
本文介绍了可以具有多个核心数据“数据库”在一个iOS应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个管理游戏,大量使用核心数据。游戏需要预先设置的,预定义的数据集,其不能被用户/系统改变;



我可以给出的最好的例子是足球管理游戏,但它可以是任何东西。在一些足球管理模拟中,他们给你场景和预设数据集。



随着用户继续游戏,他们可以保存/加载他们的进度,保存到核心数据。



除此之外,用户可以接收预定义数据的更新,或者可以购买情景数据包;



因此,可能有多个核心数据数据库(是的,我知道核心数据不是严格的数据库)或



数据的模式不会改变。



我们有:


  1. 预定义数据(默认数据),仅用于播放游戏。

  2. 用户当前的保存游戏。

  3. 用户已从互联网下载了一个场景。

  4. 问题:

  5. 问题:如何在核心数据中跟踪所有场景和所有用户保存的游戏?

  6. ol>

    这听起来像是给定时间的多个数据库。显然,应该限制用户可以进行多少个保存游戏。



    另一个解决方案是用户的设备以JSON格式导出数据的备份副本, XML,这可以作为保存数据,我也可以使用这种策略。显然,需要一些加密来防止人们通过XML简单地改变游戏中的统计数据。



    但是我从一开始就想知道什么是最好的方法为iOS设备使用Core数据处理多个核心数据数据库?



    感谢您的时间

    解决方案

    如果数据模型是相同的,你可以设置你的MOC,使它使用持久存储...一个是只读的,另一个是读/写。



    或者,您可以为每个商店使用单独的MOC。



    您唯一的决定因素,因为您几乎可以有MOC / PSC的任何组合。



    查看文档此处了解详情。






    编辑



    此问题提供的链接已过,其他人建议此链接在另一个已删除的答案中。


    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.

    The schema of the data would not change.

    So we have:

    1. Pre-defined data (Default data) that is only used for seeding the game.
    2. The user's current save game.
    3. The user has downloaded a scenario from the Internet.
    4. Problem: What happens when the user saves the game whilst on a "scenario".
    5. Problem: How do I keep track of all the scenarios and all the user saved games in core data?

    This sounds like multiple databases at a given time. Obviousily one should restrict how many save games a user can make.

    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.

    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"?

    Thanks for your time

    解决方案

    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.

    Or, you could use separate MOC for each store.

    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.


    Edit:

    The link given with this question is dead, someone else suggested this link in another deleted answer.

    这篇关于可以具有多个核心数据“数据库”在一个iOS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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