-1
我想撤销我最后一次操作。我正在使用此代码。但我无法做到这一点。请帮助。任何帮助,将apperciated在CoreData中撤消操作
首先我节省纪录
@IBAction func save(sender: AnyObject) {
let appDelegate =
UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let entity = NSEntityDescription.entityForName("Person",
inManagedObjectContext:managedContext)
entity!.uniquenessConstraints = [["name"]]
let person = NSManagedObject(entity: entity!,
insertIntoManagedObjectContext: managedContext)
//3
person.setValue(first.text, forKey: "name")
person.setValue(second.text, forKey: "age")
//4
do {
try managedContext.save()
//5
people.append(person)
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}
然后我想重做
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.managedObjectContext.undo()
谢谢先生...请发送一些代码片段。我是iOS的新手 – Rishab
哪部分? – jrturton
对于完全保存操作 – Rishab