Improve docs for the defaults key

Closes #59
This commit is contained in:
Sindre Sorhus 2022-11-09 00:48:04 +07:00
parent be7e30ba36
commit dd44190ddf
2 changed files with 9 additions and 2 deletions

View File

@ -46,7 +46,9 @@ public enum Defaults {
/** /**
Create a defaults key. Create a defaults key.
The `default` parameter can be left out if the `Value` type is an optional. - Parameter key: The key must be ASCII, not start with `@`, and cannot contain a dot (`.`).
The `default` parameter should not be used if the `Value` type is an optional.
*/ */
public init(_ key: String, default defaultValue: Value, suite: UserDefaults = .standard) { public init(_ key: String, default defaultValue: Value, suite: UserDefaults = .standard) {
self.defaultValue = defaultValue self.defaultValue = defaultValue
@ -86,6 +88,11 @@ extension Defaults {
} }
extension Defaults.Key { extension Defaults.Key {
/**
Create a defaults key.
- Parameter key: The key must be ASCII, not start with `@`, and cannot contain a dot (`.`).
*/
public convenience init<T>(_ key: String, suite: UserDefaults = .standard) where Value == T? { public convenience init<T>(_ key: String, suite: UserDefaults = .standard) where Value == T? {
self.init(key, default: nil, suite: suite) self.init(key, default: nil, suite: suite)
} }

View File

@ -80,7 +80,7 @@ If a type conforms to both `NSSecureCoding` and `Codable`, then `Codable` will b
You declare the defaults keys upfront with type and default value. You declare the defaults keys upfront with type and default value.
**Do not use a dot in the key name, because of [this bug](https://github.com/sindresorhus/Defaults/issues/59).** **The key name must be ASCII, not start with `@`, and cannot contain a dot (`.`).**
```swift ```swift
import Cocoa import Cocoa