Many click Undo or Redo(Core data) for retrieving previous tasks

HI, Could you advise me?


I got problems to work with undomanager and core data. I used a sketch tutorial which released recently by Apple. I have tableview in other uiviewcontrols. For tableview, undomanager can work well. But, for sketching , undomanager can not work well.


When I triggered sketch command to create object and save in core data which it s followed its pattern from Apple's doc.

This s NOT ok. I had to clikc many times for undo or redo.

It s ok for the code add or remove object.

" self.undoManager.registerUndo(withTarget: self, selector:#selector(DrawingViewController.removeObject(_:)), object:object) "

"self.undoManager.registerUndo(withTarget: self, selector:#selector(DrawingViewController.addObject(_:)), object:object)"



I got quite confused why the performance's undomanger s very weird( when it works with Core data ).


Thank you so much

Best regards,

You're showing the code that you're using to set up the undo, but not the code that you use to actually perform the undo.


Unless your DrawingViewController's addObject and removeObject methods modify your Core Data object model, and synchronize with Core Data properly, it's not going to work right.

Thank you for response. Yes, I had set undomanger in viewcontroller and connect with core data which it can work with another viewcontroller's tableview. I can draw and remove from saving & removing and put objects into core data. But it does not normally call back processes from undo & redo. I had to click undo&redo button around 20 - 60 times of each object.

I do not have any ideas why/how process is. It may have the right protocol which I dont know. It s a lack of tutorial and supporting documents.

I need to finish the process. If you know or any one met the same case, it will be good for me and others

Thank you so much

I tried to runloop of undomanager with whilelooop at function canPerformAction and used undomanager.undo.

" while (self.undoManager.undoActionName == "" ) {

//NSManagedObjectContext.undomanager.undo

DatabasesController.getContext().undoManager?.undo()

}"

Although, It worked but I could not do at redo. The undomanager cycle was broken suddenly.


Core data may keep all tracks change of objects before process of sending to undo and saving into core data by NSManagedObjectContext.save

which the outcome showed that core data kept all track change of objects.


I searched in google some older post in 2011 advised that coredata could be stopped keeping track with undoManager?.disableUndoRegistration and undoManager?.enableUndoRegistration(). I followed the codes but ,when run simmulation, undo&redo button was disable.


Confused! How can I do about keeping track of Coredata and undomanager?

Here's the thing.

You write that it's working but "it's too many clicks."


That means that you're not using beginundoGrouping and because of that, each individual property or attribute value change is winding up as its own undo/redo entry.

https://developer.apple.com/reference/foundation/nsundomanager/1409894-beginundogrouping

Thank you so much. I tested already and it was quite odd which I could not redo.

being undo....
many changing value and properites

..

..

undoregister-> addObject {

self.undoManager.registerUndo(withTarget: self, selector:#selector(DrawingViewController.removeObject(_:)), object:object)

}

...

..

ending undo.....


Yes, I agree with your advices. and I think so.

The great efficient core data keeps all tracks of changing value and properties.


In case complex protocol, It s very hard to decare beging undogroup nad ending undogroup.


I may consider my process how to deal with complex protocol such as copying object from core data and saving back to core data after finishing all process under normal undomanager in UIViewcontroller instead of connecting undomanager with core data.


Thank you so much.

Best regards,

Many click Undo or Redo(Core data) for retrieving previous tasks
 
 
Q