Created
September 25, 2013 15:43
-
-
Save jerryhjones/6701587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableDictionary *mutableAttributeValues = [attributeValues mutableCopy]; | |
NSString *resourceIdentifier = AFResourceIdentifierFromReferenceObject([self referenceObjectForObjectID:objectID]); | |
[childContext performBlock:^{ | |
[backingContext performBlockAndWait:^{ | |
NSManagedObjectID *backingObjectID = [self objectIDForBackingObjectForEntity:entity withResourceIdentifier:resourceIdentifier]; | |
NSManagedObject *backingObject = [backingContext existingObjectWithID:backingObjectID error:nil]; | |
[backingObject setValuesForKeysWithDictionary:mutableAttributeValues]; | |
NSString *lastModified = [[operation.response allHeaderFields] valueForKey:@"Last-Modified"]; | |
if (lastModified) { | |
[backingObject setValue:lastModified forKey:kAFIncrementalStoreLastModifiedAttributeName]; | |
} | |
NSString *etag = [[operation.response allHeaderFields] valueForKey:@"Etag"]; | |
if (etag) { | |
[backingObject setValue:etag forKey:kAFIncrementalStoreEtagAttributeName]; | |
} | |
AFSaveManagedObjectContextOrThrowInternalConsistencyException(backingContext); | |
}]; | |
[childContext performBlock:^{ | |
NSManagedObject *managedObject = [childContext objectWithID:objectID]; | |
[mutableAttributeValues addEntriesFromDictionary:attributes]; | |
[mutableAttributeValues removeObjectForKey:kAFIncrementalStoreLastModifiedAttributeName]; | |
[mutableAttributeValues removeObjectForKey:kAFIncrementalStoreEtagAttributeName]; | |
[managedObject setValuesForKeysWithDictionary:mutableAttributeValues]; | |
AFSaveManagedObjectContextOrThrowInternalConsistencyException(childContext); | |
[self notifyManagedObjectContext:context aboutRequestOperation:operation forNewValuesForObjectWithID:objectID]; | |
}]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment