Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 12, 2022
1 parent 5d1d793 commit d71bfd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Sources/Defaults/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ extension Defaults {
/**
Create a key.
- Parameter key: The key must be ASCII, not start with `@`, and cannot contain a dot (`.`).
- Parameter name: The name 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.
*/
@_alwaysEmitIntoClient
public init(
_ key: String,
_ name: String,
default defaultValue: Value,
suite: UserDefaults = .standard
) {
self.defaultValueGetter = { defaultValue }

super.init(name: key, suite: suite)
super.init(name: name, suite: suite)

if (defaultValue as? _DefaultsOptionalProtocol)?.isNil == true {
return
Expand All @@ -139,19 +139,19 @@ extension Defaults {
}
```
- Parameter key: The key must be ASCII, not start with `@`, and cannot contain a dot (`.`).
- Parameter name: The name must be ASCII, not start with `@`, and cannot contain a dot (`.`).
- Note: This initializer will not set the default value in the actual `UserDefaults`. This should not matter much though. It's only really useful if you use legacy KVO bindings.
*/
@_alwaysEmitIntoClient
public init(
_ key: String,
_ name: String,
suite: UserDefaults = .standard,
default defaultValueGetter: @escaping () -> Value
) {
self.defaultValueGetter = defaultValueGetter

super.init(name: key, suite: suite)
super.init(name: name, suite: suite)
}
}
}
Expand All @@ -161,14 +161,14 @@ extension Defaults.Key {
/**
Create a key with an optional value.
- Parameter key: The key must be ASCII, not start with `@`, and cannot contain a dot (`.`).
- Parameter name: The name must be ASCII, not start with `@`, and cannot contain a dot (`.`).
*/
@_transparent
public convenience init<T>(
_ key: String,
_ name: String,
suite: UserDefaults = .standard
) where Value == T? {
self.init(key, default: nil, suite: suite)
self.init(name, default: nil, suite: suite)
}
}

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Stores the keys.
#### `Defaults.Key` _(alias `Defaults.Keys.Key`)_

```swift
Defaults.Key<T>(_ key: String, default: T, suite: UserDefaults = .standard)
Defaults.Key<T>(_ name: String, default: T, suite: UserDefaults = .standard)
```

Type: `class`
Expand Down

0 comments on commit d71bfd8

Please sign in to comment.