MagicalRecord:多个数据库 [英] MagicalRecord: multiple databases

查看:584
本文介绍了MagicalRecord:多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MagicalRecord的应用程序,我预先填充了大量用于参考的数据。在同一数据模型中,我有用户可以在应用程序中做的事情的用户可定义的信息。

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-definable information pertaining to things the user may do in the app.

应用程序被拒绝,因为预填充的数据标记为不备份。因此,我希望将这些数据存储在单独的数据存储中,以便我可以将用户数据保留为可备份的。

The app was rejected because the pre-populated data is supposed to be marked as "do not backup". So, I'd like to have that data in a separate datastore so that I can keep the user data as backupable.

有一种方法可以使用两个单独的数据存储MagicalRecord?

Is there a way to have two separate datastores using MagicalRecord?

推荐答案

我认为这是可能的,但不是太容易。
你知道,要使用多个数据库,你应该对 PersistentStoreCoordinator 进行一些更改,因此它将有两个 PersistentStores 。之后,您的Core Data堆栈将如下所示:

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:

另一种方法是两个单独的PersistentStoreCoordinators,每个都携带一个存储。

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

在Magical Record中,用于在
NSPersistentStoreCoordinator + MagicalRecord.h 中添加商店。

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.

我还要提到,设置堆栈的整个过程进入 MagicalRecord + Setup.h

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.

这篇关于MagicalRecord:多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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