Giter Site home page Giter Site logo

rsbundomanager's Introduction

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:

self.undoManager = [[RSBUndoManager alloc] init]

Register an undo action before change you want to be able to undo:

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

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

Perform undo:

[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:

[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. To install it, simply add the following line to your Podfile:

pod "RSBUndoManager"

To install it via Carthage, simply add the following line to your Cartfile:

github "rosberry/RSBUndoManager"

Author

Anton Kormakov, [email protected]

License

RSBUndoManager is available under the MIT license. See the LICENSE file for more info.

rsbundomanager's People

Contributors

disabled avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.