问题
Once I pull data from server it gets saved in persistent store using Entity mapping
.
Then I delete
those objects manually
.
Now when I try to pull the same data again i get the error saying Mapping HTTP response to nil target object... RKObjectmapperoperation
failed.
Main thread get's blocked may be there managed context in rest kit is not having object graph after deleting. I am not sure how to solve this error I tried resetting persistent store.
UPDATE
- (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];
}
I use [self saveThreadedContext];
to save and merge thread context after deleting objects.
[context performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
withObject:notification waitUntilDone:YES];
holds lock on context
which causes the block when restkit tries to merge it's context.
wanted to know what type of concurrency to use while creating threadContext used to delete objects. i tried waitunitdone:NO
and the block didn't arise again..need some explanation why
来源:https://stackoverflow.com/questions/18533984/main-thread-blocked-after-receiving-objects-restkit-v0-20-3