此链接可能会对您有所帮助,它添加了一个用于恢复对 NSManagedObject 的更改的类别。祝你好运。
#import "NSManagedObject+RevertChanges.h"
@implementation NSManagedObject (NSManagedObject_RevertChanges)
- (void) revertChanges {
// Revert to original Values
NSDictionary *changedValues = [self changedValues];
NSDictionary *committedValues = [self committedValuesForKeys:[changedValues allKeys]];
NSEnumerator *enumerator;
id key;
enumerator = [changedValues keyEnumerator];
while ((key = [enumerator nextObject])) {
NSLog(@"Reverting field ""%@"" from ""%@"" to ""%@""", key, [changedValues objectForKey:key], [committedValues objectForKey:key]);
[self setValue:[committedValues objectForKey:key] forKey:key];
}
}