https://github.com/rnapier/appstoragekvocrash
Demonstration of AppStorage crash when modifying UserDefaults on another thread
https://github.com/rnapier/appstoragekvocrash
Last synced: about 2 months ago
JSON representation
Demonstration of AppStorage crash when modifying UserDefaults on another thread
- Host: GitHub
- URL: https://github.com/rnapier/appstoragekvocrash
- Owner: rnapier
- Created: 2023-06-16T21:11:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-16T21:12:01.000Z (almost 2 years ago)
- Last Synced: 2025-03-14T19:58:33.682Z (about 2 months ago)
- Language: Swift
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AppStorageKVOCrash
This is a demo project for FB12348064, "AppStorage crashes if UserDefaults is modified on a background thread."
When using the AppStorage property wrapper, a KVO observation is attached to UserDefaults. If UserDefaults is
modified on a background thread at the same time that the AppStorage property is being deallocated, the
application will crash. It does not matter whether the AppStorage property is the one being modified. If an
@AppStorage property is ever released, then any change to UserDefaults on a background thread can crash the
app, even though UserDefaults is documented to be thread-safe.To demonstrate the problem, run this on device or simulator. In iOS versions up to 17b1, this crashes within
a few thousand iterations, generally within a few hundred.