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
- Remove widget-specific prefix examples that implied different prefixes per process
- Emphasize that limitToInstance: false listens to ALL system UserDefaults notifications
- Clarify that prefix acts as a filter to respond only to intended suiteName changes
- Use better examples showing different App Groups rather than same-group processes
- Update performance considerations to reflect system-wide notification listening
This addresses the misconception that different processes in the same App Group
need different prefixes, when actually they typically share the same prefix
and the prefix serves to isolate different suites.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
When `limitToInstance: false`, the macro receives ALL UserDefaults notifications. Without unique prefixes, your app might react to unrelated UserDefaults changes from other parts of your app or different App Groups.
638
+
When `limitToInstance: false`, the macro listens to ALL UserDefaults change notifications from the entire system, not just your specific suite. This means it will receive notifications from:
639
+
640
+
-`UserDefaults.standard`
641
+
- Other App Groups (`group.otherapp`)
642
+
- Any other UserDefaults instances in your app
643
+
644
+
**The prefix acts as a filter** to ensure your class only responds to changes from your intended suiteName:
639
645
640
646
```swift
641
-
//Main App
647
+
// App Group suite
642
648
@ObservableDefaults(
643
649
suiteName:"group.myapp",
644
-
prefix:"main_",
650
+
prefix:"myapp_", // Only respond to keys starting with "myapp_"
645
651
limitToInstance:false
646
652
)
647
-
classAppSettings {
648
-
varuserName: String="User"// Stored as "main_userName"
653
+
classAppGroupSettings {
654
+
varsharedData: String="data"// Stored as "myapp_sharedData"
649
655
}
650
656
651
-
//Widget
657
+
//Different App Group suite
652
658
@ObservableDefaults(
653
-
suiteName:"group.myapp",
654
-
prefix:"widget_",
659
+
suiteName:"group.anotherapp",
660
+
prefix:"anotherapp_", // Only respond to keys starting with "anotherapp_"
655
661
limitToInstance:false
656
662
)
657
-
classWidgetData {
658
-
varuserName: String="Widget"// Stored as "widget_userName"
663
+
classAnotherAppSettings {
664
+
varsharedData: String="other"// Stored as "anotherapp_sharedData"
659
665
}
660
666
```
661
667
668
+
Without unique prefixes, your `AppGroupSettings` might incorrectly react to changes from `group.anotherapp` or `UserDefaults.standard`.
669
+
662
670
#### Performance Considerations
663
671
664
-
-**Default (`limitToInstance: true`)**: Better performance, only monitors specific instance changes. Use for single-process apps.
665
-
-**Cross-Process (`limitToInstance: false`)**: Necessary for App Groups but receives more notifications. Unique prefixes help filter relevant changes.
672
+
-**Default (`limitToInstance: true`)**: Better performance, only monitors changes from the specific UserDefaults instance. Recommended for single-process apps.
673
+
-**Cross-Process (`limitToInstance: false`)**: Necessary for App Groups but receives ALL system UserDefaults notifications. The prefix is essential to filter only relevant changes from your target suite.
0 commit comments