RSBUndoManager 0.2.1

RSBUndoManager 0.2.1

测试已测试
语种语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年8月

Anton Kormakov 维护。



  • 作者
  • Anton Kormakov

RSBUndoManager 是一个基于 keyPath 的撤销注册和简单内存管理的轻量级辅助工具;构建在 NSUndoManager 之上。

使用方法

准备一个 RSBUndoManager 实例

    self.undoManager = [[RSBUndoManager alloc] init]

在更改前注册撤销操作

- (id)init {
  // ...
  someObject.someKeyPath = @"oldValue"
  // ...
}

- (void)onAction {
    [self.undoManager appendTarget:someObject keyPath:@"someKeyPath"];
    someObject.someKeyPath = @"newValue"    
}

执行撤销

[self.undoManager undo];
// someObject.someKeyPath will be set to @"oldValue"

您不需要显式地注册重做操作,因此如果您想要执行重做,只需调用

[self.undoManager redo];
// someObject.someKeyPath will be set to @"newValue"

内存管理

RSBUndoManager 提供 3 种内存警告处理策略,可以通过设置 memoryWarningPolicy 属性来选择。

RSBUndoManagerMemoryWarningPolicyNone(默认)表示它将忽略内存警告并始终保留撤销堆栈中的值。如果您想自己处理内存,请使用它。

RSBUndoManagerMemoryWarningPolicyDropHalf 表示 RSBUndoManager 将尝试删除撤销堆栈中一半的操作。但由于 NSUndoManager 的限制,由于不能可靠地确定堆栈中操作的量,所以它并不精确。

RSBUndoManagerMemoryWarningPolicyDropAll 表示 RSBUndoManager 将在内存警告时删除所有撤销堆栈。如果您认为撤销堆栈的内容不是很关键,请使用它。

示例

要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install

安装

RSBUndoManager 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "RSBUndoManager"

作者

Anton Kormakov,[email protected]

许可证

RSBUndoManager 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。