Closed larryonoff closed 3 weeks ago
Hi @larryonoff, this will be fixed in #3186.
We can't subscribe to the changes for just a single key in UserDefaults
because KVO treats "compound" keys (i.e. "foo.bar") in a special way, and it that breaks observation if you were ever to do .appStorage("feature.count")
. We have no choice but to subscribe to the firehose of all user default changes.
However, because user defaults can only store very basic data, we can implement some simple remove duplicates logic.
Hi @larryonoff, this will be fixed in #3186.
We can't subscribe to the changes for just a single key in
UserDefaults
because KVO treats "compound" keys (i.e. "foo.bar") in a special way, and it that breaks observation if you were ever to do.appStorage("feature.count")
. We have no choice but to subscribe to the firehose of all user default changes.However, because user defaults can only store very basic data, we can implement some simple remove duplicates logic.
Thanks for the fix. Looking forward to the new release with the latest fixes!
PS. Sad that it's not possible to fix the issue in an optimal way.
Description
It looks that AppStorage should migrate from NSUserDefaultsDidChangeNotification to key-value observing for specific keys. According to Apple's documentation.
Checklist
main
branch of this package.Expected behavior
AppStorage triggers updates only when specific key changes.
Actual behavior
AppStorage triggers updates whenever any change occurs in NSUserDefaults.
Steps to reproduce
Check the sample project
The Composable Architecture version information
1.11.1
Destination operating system
iOS 17.5.1
Xcode version information
Version 15.4 (15F31d)
Swift Compiler version information