Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rosberry/rsbundomanager
Lightweight helper with keyPath-based undo registration
https://github.com/rosberry/rsbundomanager
ios objective-c redo undo
Last synced: 29 days ago
JSON representation
Lightweight helper with keyPath-based undo registration
- Host: GitHub
- URL: https://github.com/rosberry/rsbundomanager
- Owner: rosberry
- License: mit
- Created: 2017-08-18T10:07:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-25T07:51:28.000Z (over 7 years ago)
- Last Synced: 2024-11-30T08:16:27.215Z (about 1 month ago)
- Topics: ios, objective-c, redo, undo
- Language: Shell
- Homepage: https://rosberry.com
- Size: 33.2 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RSBUndoManager
RSBUndoManager is a lightweight helper with keyPath-based undo registration and simple memory management; built on top of NSUndoManager.
## Usage
Prepare an instance of RSBUndoManager:
```objc
self.undoManager = [[RSBUndoManager alloc] init]
```Register an undo action before change you want to be able to undo:
```objc
- (id)init {
// ...
someObject.someKeyPath = @"oldValue"
// ...
}- (void)onAction {
[self.undoManager appendTarget:someObject keyPath:@"someKeyPath"];
someObject.someKeyPath = @"newValue"
}
```Perform undo:
```objc
[self.undoManager undo];
// someObject.someKeyPath will be set to @"oldValue"
```You wonβt need to explicitly register redo action, so if you want to perform a redo just call:
```objc
[self.undoManager redo];
// someObject.someKeyPath will be set to @"newValue"
```## Memory Management
RSBUndoManager provides 3 memory warning handling policies, which can be selected by setting `memoryWarningPolicy` property.
`RSBUndoManagerMemoryWarningPolicyNone` (default) means that it will ignore memory warnings and always keep references to values in undo stack. Use it if you want to handle memory yourself.
`RSBUndoManagerMemoryWarningPolicyDropHalf` means RSBUndoManager will try to drop half of actions in undo stack. It's not precise though, since it's not always possible to reliably determine amount of actions in stack due to limitations of NSUndoManager.
`RSBUndoManagerMemoryWarningPolicyDropAll` means RSBUndoManager will drop all undo stack on memory warning. Use it if contents of undo stack are not that critical.
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Installation
RSBUndoManager is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "RSBUndoManager"
```To install it via [Carthage](https://github.com/Carthage/Carthage), simply add the following line to your Cartfile:
```
github "rosberry/RSBUndoManager"
```## Authors
Anton Kormakov, [email protected]
## About
This project is owned and maintained by Rosberry. We build mobile apps for users worldwide π.
Check out our [open source projects](https://github.com/rosberry), read [our blog](https://medium.com/@Rosberry) or give us a high-five on π¦ [@rosberryapps](http://twitter.com/RosberryApps).
## License
RSBUndoManager is available under the MIT license. See the LICENSE file for more info.