Skip to content

Instantly share code, notes, and snippets.

@jerryhjones
Created September 25, 2013 15:43
Show Gist options
  • Save jerryhjones/6701587 to your computer and use it in GitHub Desktop.
Save jerryhjones/6701587 to your computer and use it in GitHub Desktop.
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