MagicalRecord: multiple databases

前端 未结 3 1908
醉梦人生
醉梦人生 2021-02-08 11:36

I have an app that uses MagicalRecord, and I\'m pre-populating the database with a large amount of data that is used for reference. Within that same data model, I have user-defi

3条回答
  •  -上瘾入骨i
    2021-02-08 12:11

    I think it's possible, but not too easy though. As you know, to work with more than one database, you should bring some changes to your PersistentStoreCoordinator, so it will have two PersistentStores. After this, you Core Data stack would look like this: enter image description here

    The other way is two make two separate PersistentStoreCoordinators, each carrying one store.

    In Magical Record, there are several class methods for adding stores in NSPersistentStoreCoordinator+MagicalRecord.h.

    • (NSPersistentStore *) MR_addInMemoryStore;
    • (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
    • (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;

    I think, that this is the place where you could do the thing you want.

    Also i should mention, that the whole proccess of setting up the stack goes in MagicalRecord+Setup.h

    + (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName
    

    So you can add your Stores and Coordinators there. I've never managed it by myself, that was just a brief investigation of a possible solution.

提交回复
热议问题