接收对象restkit v0.20.3后主线程被阻塞

时间:2013-08-30 13:21:45

标签: ios restkit restkit-0.20

从服务器提取数据后,使用Entity mapping将其保存在持久存储中。

然后我delete这些对象manually

现在,当我尝试再次提取相同的数据时,我得到的错误是将HTTP响应映射到nil目标对象... RKObjectmapperoperation失败。

主线程被阻止可能是休息套件中的托管上下文删除后没有对象图。我不知道如何解决这个错误我尝试重置持久存储。

更新

- (void)saveThreadedContext {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self
                      selector:@selector(mergeThreadedContextChangesIntoMainContext:)
                      name:NSManagedObjectContextDidSaveNotification
                    object:self.threadedContext];

if ([[self threadedContext] hasChanges]) {

    NSError *error;

    BOOL contextDidSave = [[self threadedContext] save:&error];

    if (!contextDidSave) {

        // If the context failed to save, log out as many details as possible.
        NSLog(@"Failed to save to data store: %@", [error localizedDescription]);

        NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];

        if (detailedErrors != nil && [detailedErrors count] > 0) {

            for (NSError* detailedError in detailedErrors) {
                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
            }
        } else {
            NSLog(@"  %@", [error userInfo]);
        }
    }
}

[defaultCenter removeObserver:self name:NSManagedObjectContextDidSaveNotification object:[self threadedContext]];
self.threadedContext = nil;
}

#pragma mark -
#pragma mark PrivateMethods
- (void)mergeThreadedContextChangesIntoMainContext:(NSNotification *)notification {
NSLog(@"%@:%@ merging changes", self, NSStringFromSelector(_cmd));
 NSManagedObjectContext * context = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
[context     performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)     withObject:notification waitUntilDone:YES];
}

我在删除对象后使用[self saveThreadedContext];来保存和合并线程上下文。

[context           performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) 
        withObject:notification waitUntilDone:YES];

保持对context的锁定,当restkit尝试合并它的上下文时导致该块。 想知道在创建用于删除对象的threadContext时要使用什么类型的并发。我试过了waitunitdone:NO并且没有再出现这个块。需要一些解释为什么

0 个答案:

没有答案