You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -347,14 +347,22 @@ struct Settings {
347
347
348
348
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.
349
349
350
-
To observe a value:
350
+
To observe a value for local DefaultsKey:
351
351
```swift
352
352
let nameKey = DefaultsKey<String>("name", defaultValue: "")
353
353
Defaults.observe(key: nameKey) { update in
354
354
// here you can access `oldValue`/`newValue` and few other properties
355
355
}
356
356
```
357
357
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
+
358
366
By default we are using `[.old, .new]` options for observing, but you can provide your own:
0 commit comments