HPStorage

1.0.0

Read and write Codable types from and to disk with ease
henrik-dmg/HPStorage

What's New

Initial Release

2021-08-24T16:56:12Z

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

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 03:38:11 GMT-0900 (Hawaii-Aleutian Daylight Time)