一旦我从服务器中提取数据,它就会使用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
了,块没有再次出现..需要一些解释为什么