首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有MagicalRecord和多个商店的AFIncrementalStore

带有MagicalRecord和多个商店的AFIncrementalStore
EN

Stack Overflow用户
提问于 2014-04-11 17:33:09
回答 1查看 186关注 0票数 0

我有一个使用sqlite数据库的项目,并通过MagicalRecord库使用它:

代码语言:javascript
复制
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:storeFileName];

在当前版本的应用程序中,我通过瞬态对象使用web服务(RPC):发送请求、映射响应到对象并显示它。在数据库中,我只保存用户添加到收藏夹的项目。

现在我想用AFIncrementalStore实现API调用,用于简单的缓存和app的离线工作。第一个问题是如何在已有的CoreData堆栈中添加AFIncrementalStore?我正在尝试在内存中添加存储,例如:

代码语言:javascript
复制
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];

AFIncrementalStore *incrementalStore = (AFIncrementalStore *)[coordinator addPersistentStoreWithType:[RPCAPIIncrementalStore type] configuration:nil URL:nil options:nil error:nil];
NSError *error = nil;
if (![incrementalStore.backingPersistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

但是当我试图从我的本地数据库获取实体(我不需要对该实体进行api调用)时,我的api增量存储将处理该请求,并尝试从服务器获取该项!

我应该如何正确配置堆栈,以便高效地使用远程数据库和本地数据库中对象?对于AFIncrementalStore,这是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2014-08-27 09:57:03

下面是我用来设置AFIncrementalStore的代码。对于您的设置应该是类似的:

代码语言:javascript
复制
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"ShuffleModel.sqlite"];

    AFIncrementalStore *incrementalStore = (AFIncrementalStore *)[[NSPersistentStoreCoordinator MR_defaultStoreCoordinator] addPersistentStoreWithType:[SFIncrementalStore type] configuration:nil URL:nil options:nil error:nil];

    NSError *error = nil;

    if (![incrementalStore.backingPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSPersistentStore MR_defaultLocalStoreUrl] options:nil error:&error]){
        DDLogVerbose(@"Unresolved NSIncrementalStore error %@, %@", error, [error userInfo]);
        abort();
    }

我不确定它是否对你有帮助,但我可以通过使用NSMainQueueConcurrency来让它工作。它已经迁移到AFNetworking 2.0,并且看起来工作正常。下面是代码:https://github.com/premosystems/AFIncrementalStore

请在此处查看此问题:https://github.com/AFNetworking/AFIncrementalStore/issues/265

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23008791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档