Defaults v1.0.0 Release Notes

Release Date: 2018-10-17 // over 3 years ago
  • Key observation

    You can now observe changes to keys in a strongly-typed fashion. It even preserves the type of the oldValue and newValue keys in the change event.

    extension Defaults.Keys { static let isUnicornMode = Key\<Bool\>("isUnicornMode", default: false) }let observer = defaults.observe(.isUnicornMode) { change in// Initial eventprint(change.oldValue) //=\> falseprint(change.newValue) //=\> false// First actual eventprint(change.oldValue) //=\> falseprint(change.newValue) //=\> true} defaults[.isUnicornMode] = true
    

    Shorter syntax

     extension Defaults.Keys {- static let quality = Defaults.Key\<Double\>("quality", default: 0.8)+ static let quality = Key\<Double\>("quality", default: 0.8) }
    

    👌 Support for alternative UserDefaults suites

    let extensionDefaults = UserDefaults(suiteName: "com.unicorn.app")!extension Defaults.Keys { static let isUnicorn = Key\<Bool\>("isUnicorn", default: true, suite: extensionDefaults) } defaults[.isUnicorn]//=\> true// OrextensionDefaults[.isUnicorn]//=\> true
    

    0️⃣ Registers default values with the native UserDefaults

    When you use, for example:

    extension Defaults.Keys { static let quality = Key\<Double\>("quality", default: 0.8) }
    

    🏗 It will register 0.8 as the default value with UserDefaults, which can then be used in other contexts, like binding in Interface Builder.