I've got no idea what the proper/best solution is for this, though I'm keenly watching this thread hoping to find it, but here's what I'm doing in the meantime. Again, it feels like it's not the right/best way of doing it, hence I'm watching this thread, but it is at least working in the meantime.
I declare all my @AppStorage properties in a UserPreferences class which conforms to @ObservableObject. So I have to import Combine and SwiftUI for the class, and it does seem a little odd to import SwiftUI for a class rather than a View, but it works (or seems to).
I then just access any of my @AppStorage properties from the UserPreferences class, whether in another View or a global function or some other struct.
I know you can just re-declare the @AppStorage properties anywhere, but this way I at least only have to write the code once and don't have to worry about typing the keys/names differently or whatever.
Would love to know if there's a better way of doing this.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: