Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Defaults.updatesAll() to only listen to the keys registered in Defaults.Keys #42

Open
sindresorhus opened this issue Apr 15, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@sindresorhus
Copy link
Owner

sindresorhus commented Apr 15, 2020

UserDefaults.didChangeNotification triggers for any kind of user defaults change in the process. Even for included SDK or even Apple's APIs. This makes it both inefficient and dangerous. I just had an infinite loop where I was listening to UserDefaults.didChangeNotification and in the handler, it was setting button.imagePosition and apparently setting that properly causes a userdefault to be set internally, which resulted in an infinite loop.

I think it would be better to only listen to the keys we know about.

@sindresorhus sindresorhus added the enhancement New feature or request label Apr 15, 2020
@sindresorhus sindresorhus changed the title Change Defaults.publisherAll() to only listen to the keys registered in Defaults.Keys Add Defaults.updatesAll() to only listen to the keys registered in Defaults.Keys Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant