本文介绍了Multiplie MOC的Rest Kit Persistance / Performance问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用新版本的RestKit和多个MOC,所以这些让我有点累了。 Im使用RestKit 0.20-pre5并通过RestKit操作以及手动在整个应用程序中添加管理对象。



RestKits提供两个MOC来管理性能:mainQueue和PersistantStore Object上下文。从检查RestKits代码,所有新的被管理对象被保存到mainQueue MOC(基于RKObjectManager行433和各种指针地址的检查)。 RestKit创建的对象获得持久保存(当然,在调用保存后),但是当我在同一个mainQueue MOC中创建自己的ManagedObjects并保存时,它们在我重新启动应用程序时不会保留。 (我经常保存相关的MOC)



这是持久存储进来的地方。每当我将持久存储和mainQueue MOC一起保存时,数据仍然存在。我想象这与RKManagedObjectStore合并更改每当我调用save on persistantStoreMOC(通过通知)所以...一切正常吗?



问题是每当我保存两个上下文有一个明显的滞后,持续至少1秒(它可以变化高达3!)。这个滞后似乎增加了我创建的NSManagedObjects。我已经运行仪器,没有内存问题。我必须使用RestKits核心数据的实现不正确。



对于我使用以下方法保存的记录:

   - (void)saveContext 
{
__block BOOL _blockSuccess;
__block NSError * _blockError;

NSManagedObjectContext * persistantContext = [[[[RKObjectManager sharedManager] managedObjectStore] persistentStoreManagedObjectContext];

[globalManagedObjectContext performBlockAndWait:^ {
_blockSuccess = [globalManagedObjectContext save:& _blockError];
}];
if(!_blockSuccess)NSLog(@无法保存上下文:%@,_blockError);

[persistantContext performBlock:^ {
_blockSuccess = [persistantContext save:& _blockError];
if(!_blockSuccess)NSLog(@无法保存上下文:%@,_blockError);
}];
}

这是从一个单例对象调用,只要我们想保存应用。 (globalManagedObjectContext只是一个宏指向RestKits mainQueueObjectContext)。删除persistantContext save会删除延迟,但是当然不会保留数据。



任何人的帮助(特别是Blake Watters) b
$ b

干杯,



Aron

解决方案

我相信答案是使用RKAdditions类别添加到NSManagedObjectContext的 saveToPersistentStore:方法。



这取自, 。 / p>

使用时是否仍有问题?


This is the first time i've used the new version of RestKit and multiple MOC so this ones got my a little stumped. Im using RestKit 0.20-pre5 and am adding Managed Objects through RestKit operations as well as manually throughout the application.

RestKits provides two MOCs to manage performance: the mainQueue and PersistantStore Object contexts. From inspecting RestKits code all new managed objects are saved to the mainQueue MOC (Based on RKObjectManager line 433 and inspection of various pointer addresses). Objects created by RestKit get persisted fine (after calling a save of course) however whenever I create my own ManagedObjects in the same mainQueue MOC and save it, they do not persist when I relaunch the application. (I save the relevant MOC quite often)

This is where the persistant store comes in. Whenever I save the persistant store along with the mainQueue MOC the data persists. I imagine this has something to do with the RKManagedObjectStore merging changes whenever I call save on the persistantStoreMOC (via a notification) So... everything good right?

The problem is whenever I save both contexts there is a noticeable lag that lasts at least 1 second (it can vary up to 3!). This lag seems to increase the more NSManagedObjects I create. I have run instruments and there are no memory issues. I must be using RestKits implementation of core data incorrectly.

For the record I am saving using the following method:

- (void)saveContext
{
    __block BOOL _blockSuccess;
    __block NSError *_blockError;

    NSManagedObjectContext *persistantContext = [[[RKObjectManager sharedManager] managedObjectStore] persistentStoreManagedObjectContext];

    [globalManagedObjectContext performBlockAndWait:^{
            _blockSuccess = [globalManagedObjectContext save:&_blockError];
    }];
    if (! _blockSuccess) NSLog(@"Failed to save context: %@", _blockError);

    [persistantContext performBlock:^{
        _blockSuccess = [persistantContext save:&_blockError];
        if (! _blockSuccess) NSLog(@"Failed to save context: %@", _blockError);
    }];
}

This is called from a singleton object whenever we want to save the state of the application. (globalManagedObjectContext is simply a macro pointing to RestKits mainQueueObjectContext). Removing the persistantContext save removes the lag but of course doesn't persist the data.

Anyones help (especially Blake Watters ;) would be greatly appreciated!

Cheers,

Aron

解决方案

I believe the answer is to use the the saveToPersistentStore: method added by the RKAdditions category to NSManagedObjectContext.

This is taken from here and here.

Do you still have issues when using that?

这篇关于Multiplie MOC的Rest Kit Persistance / Performance问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:27