-
Notifications
You must be signed in to change notification settings - Fork 1
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
@AppStorage behind the scenes? #1
Comments
@malhal: Do you have insights? Perhaps using Hopper? |
I don't think they cache the value but they do cache the store. The struct |
They might only be caching the store if they have to retrieve it from the environment, that uses a lot of private methods. |
I just found a By the way they store their instances in a |
Interesting... Probably they call their wrapper class |
Based on your input and some fiddling with Hopper, I've rewritten my |
Based on what I learned on Initially I looked at how Apple implemented it in SwiftUI, but found that it is really complicated... So I created a custom solution using a I haven't used any KVO in The |
After having written Unit tests for |
Sadly I was not able to build a SPM package, as I basically need multiple versions based on the same code: one for iOS13 and one for iOS14. And if I would want to compare the demo app to iOS15 behaviour (without any shims) without modifying the code, I have to provide a library/package for iOS15. |
The current implementation of
@AppStorage
for iOS 13 is fully relying on theUserDefaults
data store:We do not keep track of the current value but fully rely on some caching by the store. Through KVO we observe whether the value has changed and trigger
objectWillChange
on our storage wrapper.How is Apple doing this on iOS 14? Do they cache the value for quick access?
Latest version of the source: AppStorage.swift
The text was updated successfully, but these errors were encountered: