StoredIn is a simple property wrapper library to store any value in anywhere

Related tags

Utility StoredIn
Overview

StoredIn

Swift Package Manager compatible

StoredIn is a simple property wrapper library to store any value in anywhere.

Installation

Please use the Swift Package Manager.

dependencies: [
    .package(url: "https://github.com/moriturus/StoredIn.git", .upToNextMajor(from: "1.0.0"))
]

Usage

import StoredIn

// implement the `Store` where your data are saved.
final class SharedDictionary: Store {
    var inner: [String: Any] = [:]
    
    func containsValue(forKey key: String) -> Bool {
        self.inner[key] != nil
    }
    
    func value<S>(forKey key: String) -> S? where S : Storable {
        self.inner[key] as? S
    }
    
    func set<S>(value: S, forKey key: String) where S : Storable {
        self.inner[key] = value
    }
}

let sharedDictionary = SharedDictionary()

struct Foo {
    @StoredIn(store: sharedDictionary, key: "key", default: 0, strategy: .default)
    var value: Int
}

var foo = Foo()
let x = foo.value // x == 0
foo.value = 1
sharedDictionary.inner["key"] as? Int == foo.value // true

Strategy

  • default
    • The default strategy. You can change stored value as many times as you need.
  • once
    • You can store a value only once.

License

This software is released under the MIT License.
See LICENSE file for details.

You might also like...
Measure the power output from a car or any moving vehicle from GPS data and weight
Measure the power output from a car or any moving vehicle from GPS data and weight

GPSDyno Measure the power output from a car or any moving vehicle from weight and GPS data of your iOS device. This is just a example project and shou

Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Swift For Any Measure: Simplified

AnyMeasure Swift For Any Measure: Simplified A clean, Swift interface for Foundation.Measurement Read my post about it here. Requirements: Swift 4.0+

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

💡 A light Swift wrapper around Objective-C Runtime
💡 A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift.

UTIKit UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift. Features UTIKit is a full featured library including entire UTI functions. Conver

Swift wrapper for PuLP module.

SwiftPuLP Wraps Python Linear Programming PuLP module. Requirements Requires PuLP to be installed, and may require PYTHON_LIBRARY environment variable

Dungeon Crawl: Stone Soup iOS Webtiles wrapper

dcss-ios Dungeon Crawl: Stone Soup iOS Webtiles wrapper Summary This project aims to make DCSS webtiles a joy to play on any iOS device without an ext

Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

Owner
Henrique Sasaki Yuya
Henrique Sasaki Yuya
Backports the new @Invalidating property wrapper to older platforms

ViewInvalidating A property wrapper that backports the new @Invalidating property wrapper to older versions of iOS/tvOS/macOS. For more information on

Suyash Srijan 61 Nov 23, 2022
`Republished` is a property wrapper enabling nested ObservableObjects in SwiftUI.

Republished The @Republished proprty wrapper allows an ObservableObject nested within another ObservableObject to naturally notify SwiftUI of changes.

Adam Zethraeus 13 Dec 5, 2022
A Swift Encoder for encoding any Encodable value into an array of URLQueryItem.

URLQueryItemEncoder A Swift Encoder for encoding any Encodable value into an array of URLQueryItem. As part of the SE-0166, Swift has a foundation for

Pitiphong Phongpattranont 60 Aug 21, 2022
Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Tim Oliver 3 May 23, 2021
A Collection of useful Swift property wrappers to make coding easier

Swift Property Wrappers A Collection of useful Swift property wrappers to make c

Gordan Glavaš 2 Jan 28, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022
App Store Receipt Validation

Kvitto "Kvitto, it means Receipt in Swedish. The trend of using Swedish words for libraries is pretty big" -- Hugo Tunius via Twitter Allows parsing a

Cocoanetics 288 Sep 12, 2022
Store values using unique, randomly generated identifiers

Storage Store values using unique, randomly generated identifiers. This packages consists of three types: A Storage class, a UniqueIdentifiable protoc

Jordan Baird 1 Feb 23, 2022
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 219 Aug 30, 2022