Skip to content

Commit

Permalink
fix not works in preview mode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fatbobman committed Nov 2, 2024
1 parent f3a5dcd commit d5b7a9c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public class Test2 {
- **Key Prefixes**: Use the `prefix` parameter to prevent key collisions when multiple classes use the same property names.
- **Custom Keys**: Use `@DefaultsKey` to specify custom keys for properties.
- **Prefixe Charters**: The prefix must not contain '.' characters.
_ **Preview Environment**: Due to functionality limitations, instances in preview mode cannot respond to external UserDefaults changes.

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ extension DefaultsBackedMacro: AccessorMacro {
"""
set {
let key = _prefix + "\(raw: keyString)"
if _isExternalNotificationDisabled || _ignoredKeyPathsForExternalUpdates.contains(\\.\(identifier)) {
if _isExternalNotificationDisabled ||
_ignoredKeyPathsForExternalUpdates.contains(\\.\(identifier)) ||
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
withMutation(keyPath: \\.\(identifier)) {
UserDefaultsWrapper.setValue(key, newValue, _userDefaults)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ extension ObservableDefaultsMacros: MemberMacro {
private var observer: DefaultsObservation?
/// The observation registrar is used to manage the observation of changes to UserDefaults.
/// It ensures that the observer is properly registered and deregistered when the instance is created and deinitialized.
/// It ensures that the observer is properly registered and deregistered when the instance is created and deInitialized.
/// The registrar is accessed through the `_$observationRegistrar` property.
///
/// - Note: This property is internal and can be accessed within the same module.
Expand Down

0 comments on commit d5b7a9c

Please sign in to comment.