Skip to content

Commit

Permalink
Fix crash due to execution of RKDeleteInvalidNewManagedObject from …
Browse files Browse the repository at this point in the history
…outside of the dispatch queue of the `NSManagedObjectContext` that owns the object. fixes RestKit#1251
  • Loading branch information
blakewatters committed Feb 22, 2013
1 parent c7a53f3 commit 47eed61
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Code/CoreData/RKManagedObjectMappingOperationDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static id RKMutableCollectionValueWithObjectForKeyPath(id object, NSString *keyP
return nil;
}

// Pre-condition: invoked from the managed object context of the given object
static BOOL RKDeleteInvalidNewManagedObject(NSManagedObject *managedObject)
{
if ([managedObject isKindOfClass:[NSManagedObject class]] && [managedObject managedObjectContext] && [managedObject isNew]) {
Expand Down Expand Up @@ -326,7 +327,9 @@ - (BOOL)commitChangesForMappingOperation:(RKMappingOperation *)mappingOperation
// Attempt to establish the connections and delete the object if its invalid once we are done
NSOperationQueue *operationQueue = self.operationQueue ?: [NSOperationQueue currentQueue];
NSBlockOperation *deletionOperation = [NSBlockOperation blockOperationWithBlock:^{
RKDeleteInvalidNewManagedObject(mappingOperation.destinationObject);
[[(NSManagedObject *)mappingOperation.destinationObject managedObjectContext] performBlockAndWait:^{
RKDeleteInvalidNewManagedObject(mappingOperation.destinationObject);
}];
}];

for (RKConnectionDescription *connection in connections) {
Expand Down

0 comments on commit 47eed61

Please sign in to comment.