r/macosprogramming • u/B8edbreth • Jan 31 '24
Would someone mind explaining how to use this:
regsiterUndoWithTarget:handler:
I'm not particularly good at completion blocks and I can't find an example of this online so I'm wondering if someone could show me a quick example of how to use it... In objective-c if possible please
1
Upvotes
2
u/idelovski Jan 31 '24
Does this help?
https://medium.com/liveop-x-team/using-nsundomanager-for-fun-and-profit-16a8d7aa77be
2
u/david_phillip_oster Feb 01 '24
I prefer to do it the oldfashioned way:
that is, tell the undomanager to create an object that behaves like self, but instead of calling the method, create an NSInvocation - a frozen call to self with a selector and arguments, that would undo the effect of this method on the model, and push that on the undo stack. (Example happens to be from iOS, but macOS looks much the same.)