Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

nsmanagedobject - 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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...