【发布时间】:2024-05-19 03:25:02
【问题描述】:
我想撤消上一次操作。我正在使用此代码。但我无法做到这一点。请帮助。任何帮助都会得到帮助
首先我要保存记录
@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()
【问题讨论】: