Swiftpack.co - henrik-dmg/HPStorage as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by henrik-dmg.
henrik-dmg/HPStorage 1.0.0
Read and write Codable types from and to disk with ease
⭐️ 0
🕓 2 years ago
.package(url: "https://github.com/henrik-dmg/HPStorage.git", from: "1.0.0")

HPStorage

HPStorage is a set of utilities to conveniently manage disk storage in your Swift applications. It includes a helper type and a property wrapper which both built on top of FileManager extensions which are also publicly available.

Installation

To use HPStorage, simply add .package(url: "https://github.com/henrik-dmg/HPStorage", from: "1.0.0") to your Package.swift or the URL in Xcode when it prompts you for it

Usage

FileStorage property wrapper

Use it like other property wrappers, like AppStorage for example.

struct MyView: View {

    @FileStorage("yourFilename")
    private var storedValue: SomeCodableStruct

    var body: some View {
        Button("Do something") {
          storedValue = //... assign new value
        }
    }

}

Notice in the example above that you can mutate the wrapped value of FileStorage even when contained in value types

FileUtility helper

FileUtility is the worker type used by FileStorage. You can use it directly though as following:

let utility = FileUtility(directory: .caches())

// Writing values
try utility.writeValue(someEncodableValue, fileName: "yourFilename")

// Reading values
let someDecodableValue: SomeCodableStruct = try utility.readValue(atFile: "yourFilename")

Contributors

GitHub

link
Stars: 0
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Initial Release
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics