Skip to content

Commit ed0115d

Browse files
authored
Updated KVO section of README
Added KVO code snippet in README for key defined in extension of DefaultsKeys
1 parent 91dc537 commit ed0115d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,22 @@ struct Settings {
347347

348348
KVO is supported for all the types that are `DefaultsSerializable`. However, if you have a custom type, it needs to have correctly defined bridges and serialization in them.
349349

350-
To observe a value:
350+
To observe a value for local DefaultsKey:
351351
```swift
352352
let nameKey = DefaultsKey<String>("name", defaultValue: "")
353353
Defaults.observe(key: nameKey) { update in
354354
// here you can access `oldValue`/`newValue` and few other properties
355355
}
356356
```
357357

358+
To observe a value for a key defined in DefaultsKeys extension:
359+
```swift
360+
Defaults.observe(\.nameKey) { update in
361+
// here you can access `oldValue`/`newValue` and few other properties
362+
}
363+
```
364+
365+
358366
By default we are using `[.old, .new]` options for observing, but you can provide your own:
359367
```swift
360368
Defaults.observe(key: nameKey, options: [.initial, .old, .new]) { _ in }

0 commit comments

Comments
 (0)