gpt4 book ai didi

ios - MagicalRecord:多个数据库

转载 作者:技术小花猫 更新时间:2023-10-29 10:58:51 26 4
gpt4 key购买 nike

我有一个使用 MagicalRecord 的应用程序,我正在用大量数据预填充数据库以供引用。在同一数据模型中,我拥有与用户可能在应用程序中执行的操作相关的用户可定义信息。

该应用被拒绝,因为预填充的数据应该被标记为“不备份”。因此,我想将该数据保存在单独的数据存储中,以便我可以将用户数据保持为可备份的。

有没有办法使用 MagicalRecord 拥有两个独立的数据存储?

最佳答案

我认为这是可能的,但不是太容易。如您所知,要使用多个数据库,您应该对 PersistentStoreCoordinator 进行一些更改,这样它将有两个 PersistentStores。在此之后,您的核心数据堆栈将如下所示: enter image description here

另一种方式是创建两个独立的 PersistentStoreCoordinator,每个都携带一个 store。

在Magical Record中,有几个添加店铺的类方法NSPersistentStoreCoordinator+MagicalRecord.h

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

我认为,这是您可以做您想做的事情的地方。

我还应该提到,设置堆栈的整个过程都在 MagicalRecord+Setup.h

+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName

所以你可以在那里添加你的商店和协调员。我从来没有自己管理过它,那只是对可能的解决方案的简短调查。

关于ios - MagicalRecord:多个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11123867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com