how to discard CoreData changes made to an instance of NSManagedObject when POST/PUT request of this object fails in RKObjectManager?
NSManagedObject *object = ...;
[object setValue:@"test" forKey: @"test"];
[[RKObjectManager sharedManager] postObject:object
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { NSLog(@"success, nothing to do"); }
failure:^(RKObjectRequestOperation *operation, NSError *error) {
// I want to discard changes made to object here
}
UPDATE: RestKit 0.20
I know nothing about RKObjectManager
, but in order to discard changes to NSManagedObject instance you could call:
[object.managedObjectContext refreshObject:object mergeChanges:NO]
This will discard all changes and turn the object into fault.
see here
Swift solution:
import CoreData
extension NSManagedObject {
func cancelChanges() {
managedObjectContext?.refresh(self, mergeChanges: false)
}
}
Using:
object.cancelChanges()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With