Swiftpack.co -  almazrafi/KeyValueContainer as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
almazrafi/KeyValueContainer
Type-safe containers for key-value storage
.package(url: "https://github.com/almazrafi/KeyValueContainer.git", from: "1.0.1")

KeyValueContainer

Build Status Codecov Cocoapods Carthage compatible SPM compatible Platforms Xcode Swift License

Requirements

  • iOS 10.0+ / macOS 10.12+ / watchOS 3.0+ / tvOS 10.0+
  • Xcode 10.2+
  • Swift 5.0+

Usage

Declare a container:

extension PersistentStorage {
    var foobar: KeyValueContainer<Int> {
        makeContainer()
    }
}

This will create a container with the same key as property name: "foobar"

Reading a value from the storage:

let foobar = PersistentStorage.default.foobar.value

Same as using UserDefaults:

let foobar = UserDefaults.standard.integer(forKey: "foobar")

Writing a value to the storage:

PersistentStorage.default.foobar.value = 123

Same as using UserDefaults:

UserDefaults.standard.set(123, forKey: "foobar")

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate KeyValueContainer into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'KeyValueContainer'
end

Finally run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate KeyValueContainer into your Xcode project using Carthage, specify it in your Cartfile:

github "almazrafi/KeyValueContainer" ~> 1.0.1

Finally run carthage update to build the framework and drag the built KeyValueContainer.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate KeyValueContainer into your Xcode project using Swift Package Manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/almazrafi/KeyValueContainer.git", from: "1.0.1")

and then specify "KeyValueContainer" as a dependency of the Target in which you wish to use KeyValueContainer.

Here's an example Package.swift:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(name: "MyPackage", targets: ["MyPackage"])
    ],
    dependencies: [
        .package(url: "https://github.com/almazrafi/KeyValueContainer.git", from: "1.0.1")
    ],
    targets: [
        .target(name: "MyPackage", dependencies: ["KeyValueContainer"])
    ]
)

Communication

  • If you need help, open an issue.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

License

KeyValueContainer is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 6
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

1.0.1
34 weeks ago

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