Swiftpack.co - stateman92/KeyValueStorage as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by stateman92.
stateman92/KeyValueStorage 0.0.2
Store any data on the device! 🧳
⭐️ 2
🕓 51 weeks ago
iOS macOS
.package(url: "https://github.com/stateman92/KeyValueStorage.git", from: "0.0.2")

KeyValueStorage

Store any data on the device! 🧳

Setup

Add the following to Package.swift:

.package(url: "https://github.com/stateman92/KeyValueStorage", exact: .init(0, 0, 2))

Or add the package in Xcode.

Usage

import KeyValueStorage

struct CodablePage {
    let text: String
}

extension CodablePage: Codable {}

let coder = Coder()
let object = CodablePage(text: "Text")
let data: Data? = coder.encode(object, type: .json)
let storageData = UserDefaultsKeyValueStorage().do {
    let key = "KEY"
    $0.save(data, forKey: key)
    return $0.get(forKey: key)
}
let result: CodablePage? = coder.decode(storageData, type: .json)
// object.text == result?.text

For details see the Example app.

Tests

The library is well-tested with practically 100% coverage (96.0%).

GitHub

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

Related Packages

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