Swiftpack.co - Package - sindresorhus/Defaults

404: Not Found

Github

link
Stars: 408
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v3.0.0 - Sep 11, 2019

Breaking

  • Require Xcode 11 and Swift 5.1 for building https://github.com/sindresorhus/Defaults/commit/90ac6f88021e22d58b109b71866bd21471b898fe
  • Switch from defaults to Defaults https://github.com/sindresorhus/Defaults/commit/90ac6f88021e22d58b109b71866bd21471b898fe Example: defaults[.unicorn]Defaults[.unicorn] Example: defaults.observableDefaults.observable
  • Rename defaults.clear to Defaults.removeAll and make it a static method https://github.com/sindresorhus/Defaults/commit/27c9997134dacd097b912a39a685ea71a0a57b89

Enhancements

  • Add .reset() method to reset the given keys back to their default value https://github.com/sindresorhus/Defaults/commit/d1e42154f9a2c9c7375849bd376b99a48deda47b

v2.0.2 - Jul 25, 2019

  • Fix the source file location for SwiftPM https://github.com/sindresorhus/Defaults/commit/674fde4974ffeb8cb4de02d4977a20e74dcea40a

v2.0.1 - Jul 8, 2019

  • Fix Swift 5 upgrade warning https://github.com/sindresorhus/Defaults/commit/865a4b0ff33d1e4b04382d60e808d16ce53c0775

v2.0.0 - Apr 5, 2019

  • Upgrade to and require Swift 5. https://github.com/sindresorhus/Defaults/commit/908d3b4ee17e4f7534750d55a0fa2e532ff4f18b

v1.0.0 - Oct 17, 2018

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 event
	print(change.oldValue)
	//=> false
	print(change.newValue)
	//=> false

	// First actual event
	print(change.oldValue)
	//=> false
	print(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

// Or

extensionDefaults[.isUnicorn]
//=> true

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.