Post

Replies

Boosts

Views

Activity

Reply to After manually adding a PKStroke, the UndoManager no longer works
@WillBishop Thanks for finding a solution to this problem. I just wanted to add the "Redo" method in case everyone else need it: self.undoManager?.groupsByEvent = false self.drawing.strokes.append(YOURCUSTOMPKSTROKE) for (index, _) in self.drawing.strokes.enumerated() { self.undoManager?.beginUndoGrouping() self.undoManager?.registerUndo(withTarget: self, handler: { $0.drawing.strokes.remove(at: index) self.undoManager?.registerUndo(withTarget: self, handler: { // redo here $0.drawing.strokes.append(YOURCUSTOMPKSTROKE) }) }) self.undoManager?.endUndoGrouping() } self.undoManager?.groupsByEvent = true
Oct ’24