有没有办法查看撤消堆栈?

发布于 2024-08-07 15:28:33 字数 141 浏览 1 评论 0原文

我正在学习撤消,并且我想要一种方法来查看 undoManager 中的撤消对象 (NSIn Vocations),以便我可以看到发生了什么。我在文档中看不到类似的内容,但也许有人知道一种方法。

谢谢。

I'm learning about undo, and I'd like a way to peek into the undo objects (NSInvocations) in the undoManager so I can see what's going on. I couldn't see anything like this in the docs, but maybe someone knows a way.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杯别 2024-08-14 15:28:33

您可以使用

class-dump -C NSUndo /System/Library/Frameworks/Foundation.framework/Foundation

来了解undo相关类的内部结构。你会发现
NSUndoManager 有两个实例变量,名为 _undoStack 和 _redoStack。它的结构非常明显,因此您可以编写一个打印堆栈的小方法。我发现这对于调试撤消相关问题非常方便。

You can use

class-dump -C NSUndo /System/Library/Frameworks/Foundation.framework/Foundation

to find out about the inner structure of the undo related classes. You will find that
the NSUndoManager has two instance variables named _undoStack and _redoStack. It's pretty obvious how it's structured, so you can write a little method printing the stack. I found that quite handy for debugging undo related problems.

廻憶裏菂餘溫 2024-08-14 15:28:33

您使用核心数据吗? Core Data 提供自动撤消/重做支持。否则,NSUndoManager 将有一个空堆栈。

我想我对你的问题是,你为什么要查看堆栈?实际上,您实际上没有理由必须查看撤消管理器的堆栈。如果您正在寻找有关如何创建撤消操作并将其推送到堆栈上的建议,这里有一个 关于如何做到这一点的很好的概述。 Apple 关于这个主题的文档也相当不错。我特别喜欢基于调用的方法。

Are you using Core Data? Core Data provides automatic undo/redo support. Otherwise, the NSUndoManager will have an empty stack.

I suppose my question to you would be, why do you want to look at the stack? In practice, there's really no reason you should have to look at the undo manager's stack. If you're looking for advice on how to create undo actions and push them on the stack, here's a pretty good overview on how to do that. Apple's documentation on the subject is also quite good. I'm especially fond of the invocation-based method.

只涨不跌 2024-08-14 15:28:33

您可以打印撤消管理器的 _undoStack 私有属性:

let undoStack = object_getIvar(undoManager, class_getInstanceVariable(UndoManager.self, "_undoStack")!)

print(undostack.debugDescription)

基于此要点

You can print your undo manager's _undoStack private property:

let undoStack = object_getIvar(undoManager, class_getInstanceVariable(UndoManager.self, "_undoStack")!)

print(undostack.debugDescription)

Based on this gist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文