objective c - Can I have multiple Core data handlers for one iphone app? -


i'm wanting build app 2 core data handlers 1 iphone app.

the app sports game pre-filled information. lets call prefilleddb reference. prefilleddb read-only, not want user add/edit/delete or change in this.

the second db ("gamedb") have same core data relationships/models/entities , structure.

when user selects "new game", blank/empty gamedb , fill prefilleddb contents, , "continue game" use prefilleddb, assuming not empty.

however, i'm not sure if right way it. question therefore best way handle kind of processing. in-built migration system better dropping/recreating databases -- or perhaps using sqlite prefilleddb , filling gamedb contents?

any on great.

the prefilled persistent store have readonly if ships in app bundle in app bundle read only. make use of data in readwrite persistent store, need copy data persistent store outside app bundle e.g. in documents directory app.

you have 2 ways of doing this:

1) simplest: create new persistent store each game. in case copy prefilled persistent store file app directory documents directory while in process renaming current game name. open file gamedb , automatically populated preexisting data. downside of system have large number of files, 1 each game, , data not shared between them.

2) best: use 2 persistent stores simultaneously in same context. more complicated set gives greater flexibility. trick create single abstract subentity e.g. opponent , 2 concrete subentities identical save names e.g. preopponent , gameopponent. using configurations option in data model, assign preopponent prefilled persistent store , gameopponent gamedb persistent store. write code in opponentclass clone new gameopponent instance. when new game starts, clone instances prefilled 'gamedb'. newly cloned gameopponent instances automatically write gamedb persistent store.

the advantage of latter system have active data in 1 readwrite persistent store can manipulate needed. e.g. check previous game or clone previous game create novel starting point new game.

marcus zarrus had code on site showing how set automatic cloning managed objects.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -