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
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -446,6 +446,58 @@ class AppearanceSettings {
446
446
447
447
When a type conforms to both `RawRepresentable` and `Codable`, the library will prioritize the `RawRepresentable` storage method, storing values using their raw representation rather than JSON encoding. This ensures backward compatibility with existing data and provides more efficient storage for enum types.
448
448
449
+
### Storage Resolution Rules (Important for Direct Key Access)
450
+
451
+
These rules apply to both `@ObservableDefaults` (`UserDefaults`) and `@ObservableCloud` (`NSUbiquitousKeyValueStore`).
452
+
When a type matches multiple constraints, the implementation chooses the most specific path in this order:
For `RawRepresentable & PropertyListValue` (including `RawRepresentable & PropertyListValue & Codable`):
474
+
475
+
- Read attempts `rawValue` format first.
476
+
- If that fails, read falls back to direct `PropertyListValue` casting.
477
+
478
+
This fallback keeps older data readable when a property was previously persisted via direct PropertyList format and later evolved to a `RawRepresentable` type.
479
+
480
+
#### Consistency for Manual `UserDefaults` / Cloud Reads and Writes
481
+
482
+
If you also read/write these keys directly outside the macros, use the same format rules to avoid mismatches.
483
+
484
+
- Use `rawValue` for all `RawRepresentable`-based properties.
485
+
- Use direct PropertyList values for PropertyList paths.
486
+
- Use JSON `Data` only for `Codable`-only properties.
487
+
- Key naming follows macro key resolution:
488
+
- default: `prefix + propertyName`
489
+
- custom key: `@DefaultsKey` / `@CloudKey`
490
+
491
+
Example (`UserDefaults`):
492
+
493
+
```swift
494
+
// For RawRepresentable-backed property (rawValue: String)
0 commit comments