DefaultsKit
DefaultsKit leverages Swift 4's powerful Codable capabilities to provide a Simple and Strongly Typed wrapper on top of UserDefaults. It uses less than 70 lines of code to acomplish this.
Installation >> instructions
<<
Usage
Instantiate, or get a shared
instance of Defaults
Then:
Check if a key has a value:
If you just need to know that a key/value pair exists, without actually using the value, use the
has()
method instead of the optionalget(for:key)
. For complex objects it will prevent any unnecessary deserialization.
Implicit Member Expression
You can find a convenience wrapper for your keys by extending DefaultsKey
. This allows you use Implicit Member Expression:
Complex objects
To store a complex object just conform to the Codable protocol:
Then:
And finally:
Nested Objects
You can also use nested objects as long as they conform to the Codable
protocol:
License
DefaultsKit is released under the MIT license. See LICENSE for details.
Thank you ?