Introducing EasyStash — Easy data persistence in Swift

EasyStash is an easy and lightweight persistence framework in Swift. With simple abstraction over NSCache and FileManager, it saves us from tedious work of saving and loading objects. There are no clever async, expiry handling or caching strategy for now, just save and load.

[x] Swift 5

[x] Support iOS, macOS, tvOS

[x] Synchronous APIs with explicit try catch

[x] Persist UIImage/NSImage

[x] Persist Codable objects, including primitive types

[x] Persist Data

[x] Test coverage

Usage

The main and only class is Storage which encapsulates memory and disk cache. All operations involving disk are error prone, we need to handle error explicitly.

With Options, we can customize folder name, searchPathDirectory, encoder and decoder for Codable

Saving and loading Data

Saving and loading primitives

Although primitives like Int, String, Bool conform to Codable, they can't be serialized into Data using JSONEncoder because json needs root object. This framework handles this case, so you can just save and load as normal