Latest 0.1.0
Homepage https://github.com/Soul-Beats/SLVCStatePreservation
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

SLVCStatePreservation is a tool library which stores your last states of view controllers and restores these states easily. It is written by Swift, but compatible with Objective-C, referring to Using Swift with Cocoa and Objective-C (Swift 2.2). For keeping the states persistence, I prefer the technology of Archive.

Installation

Cocoapods

use_ frameworks!

pod 'SLVCStatePreservation', '~> 0.1.0'

Manually

Add Source directory into your project, and it’s better to rename it to SLVCStatePreservation.

Usage

Assume that the key of the state is key. For operating states using syntax like array, you need to override the method keysOfStates(), for example:

override func keysOfStates() -> [String] {
        return ["key"]
    }

Read Preserved States

Do one of the following statements in any subclasses of UIViewController:

  • let state = states["key"]
  • let state = self["key"]

Because key is in the return array of the keysOfStates() with the index 0, the following statements are the same with above:

  • let state = stateAtIndex[0]
  • let state = self[0]

Write New Preserved States

Do one of the following statements in any subclasses of UIViewController:

  • states["key"] = newState
  • self["key"] = newState
  • setState(newState, atIndex: 0)
  • self[0] = newState

IMPORTANT: If newState is nil, the state referred by key will be removed.

At any appropriate time, call synchronize() to write to the file system for persistence.

Remove All Preserved States of a View Controller

Do one of the following statements in any subclasses of UIViewController, like ViewController:

  • states.removeAll()
  • states = [:]
  • VCStatePreservation.sharedInstance.delete(statesOfViewControllerClass: self.dynamicType)
  • VCStatePreservation.sharedInstance.delete(statesOfViewControllerClass: ViewController.self)

At any appropriate time, call synchronize() to write to the file system for persistence.

Remove All Preserved States of All View Controllers

Do the following statements anywhere:

  • VCStatePreservation.sharedInstance.deleteAll()

MIT License

The MIT License (MIT)

Copyright (c) 2015 Soul

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Latest podspec

{
    "name": "SLVCStatePreservation",
    "version": "0.1.0",
    "summary": "A Class Preserving Last States of the View Controller",
    "homepage": "https://github.com/Soul-Beats/SLVCStatePreservation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "My Soul, Your Beats!": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/Soul-Beats/SLVCStatePreservation.git",
        "tag": "0.1.0"
    },
    "source_files": "Source/**/*",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This