Yesterday I was telling you about the many preferences / settings of @IceCubesApp, today I'll show you the code

@dimillian @IceCubesApp never thought to embed app storage in an observable object before. How do you go about accessing them outside the view, or do you not need to?

@phill @dimillian @IceCubesApp unfortunately AppStorage does not currently work in Observable on iOS 17.

@alpennec @phill @IceCubesApp actually observable is for some other published properties on there. AppStorage not working as published property on iOS 17 would be crazy. I guess it’s a bug? Also I’ve made it a singleton to access it anywhere else than in views.

Follow

@dimillian @alpennec @IceCubesApp that's neat, thanks for sharing.

I went down the route of mimicking environment keys, which works great, but not sure it was worth all the time/effort replicating AppStorage 😛

@phill @alpennec @IceCubesApp so you inject all of them at the app level and then retrieve like env?

@dimillian @alpennec @IceCubesApp I used to use the environment exclusively (2nd photo), but views weren't notified of changes. This was fine for most of my views, but some needed to be live.

For these I have a @Setting property wrapper mapped to a StateObject that listens for changes in the defaults. I switch between the two depending on what I need, but they all utilise the same keys.

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.