如何将MagicalRecord与AFIncrementalStore一起使用

时间:2013-09-02 09:52:17

标签: ios objective-c xcode magicalrecord

如果有人能够MagicalRecordAFIncrementalStore一起使用,请解释如何一起使用它们?

我正在尝试将MagicalRecord配置为使用AFIncrementalStore但是当我提取获取请求时,应用会挂起。我可以看到AFIncrementalStore向API服务器发出请求并接收响应,但之后UI变得没有响应。

以下是MagicalRecord + AFIncrementalStore的配置:

NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];

AFIncrementalStore *incrementalStore = (AFIncrementalStore *)[persistentStoreCoordinator addPersistentStoreWithType:[APIIncrementalStore type] configuration:nil URL:nil options:nil error:nil];

NSDictionary *options = @{
    NSInferMappingModelAutomaticallyOption : @(YES),
    NSMigratePersistentStoresAutomaticallyOption: @(YES)
};

[incrementalStore.backingPersistentStoreCoordinator MR_addSqliteStoreNamed:@"DB.sqlite" withOptions:options];
[NSPersistentStore MR_setDefaultPersistentStore:incrementalStore];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:incrementalStore.persistentStoreCoordinator];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:incrementalStore.persistentStoreCoordinator];

获取请求如下所示:

[Card MR_fetchAllSortedBy:@"number" ascending:YES withPredicate:nil groupBy:nil delegate:self];

0 个答案:

没有答案