-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