0

i want to be able to run 2 "databases" one for seed and one for userData i'm using MagicalRecord but can't wrap my head around on how to accomplish this. so far i think i need a new NSManagedObjectContext for handling the 2nd database, i think. but how do i call it ? also how do i init 2 databases "momd" i googld all day today but either i'm searching for the wrong term or i don't know what. could someone point me in a direction ?

OR

should i just disband magical record and try it the hard way and figure out a way to have 2 sqlite's managed

KennyVB
  • 745
  • 2
  • 9
  • 28
  • I don't think its better idea to create multiple sqlite or datamodel of coredata. Why not you manage other sqlite tables/entity seperately in single datamodel/sqlite? – Tirth Jan 23 '14 at 17:13
  • erhm because i'm having big problems. i can't update the datamodel without getting double entities. if you know a way to NOT to get double entities please do tell :) – KennyVB Jan 23 '14 at 17:18
  • Yes their is way update your entities name with some suffix/prefix identifiers then you can easily discriminate it at on run time. Suppose "user" an entity then you can keep two entity like "user_main" and "user_dummy" – Tirth Jan 23 '14 at 17:20
  • http://stackoverflow.com/questions/13109257/is-it-possible-to-have-multiple-core-data-databases-on-one-ios-app – Tirth Jan 23 '14 at 17:27
  • @Reformer damm would have hoped for a example code. read that post allrdy also what it links to... but still can't wrap my head around it – KennyVB Jan 23 '14 at 17:32

1 Answers1

0

It sounds like you really need to get a handle on Core Data itself prior to using MagicalRecord. Core Data can most certainly handle this scenario for you, however you will need to keep track of two different stacks, so two complete sets of NSManagedObjectContexts, NSPersistentStoreCoordinators, NSManagedObjectModels and NSPersistentStores.

If you want a "seed" data store , I suggest you do the following (besides really understanding how Core Data works):

  • Build your seed data store prior to application build
  • Seed your data store
  • Make a copy, and deploy that with your app in the app bundle. You'll likely need to reference it using [[NSBundle mainBundle] pathForResource:ofType:].
  • Copy this seed data store from your application bundle to your destination directory. DO NOT TRY TO MODIFY THE SEED DATA STORE DIRECTLY IN THE APP BUNDLE. Doing so will most likely not be possible anyway since modifying the app bundle is not allowed.
  • Once your seed data store is fully copied, load up the Core Data stack, through MagicalRecord or otherwise.

There is no sample code for this, as this is something you'll need to work out for yourself.

casademora
  • 67,775
  • 17
  • 69
  • 78