I have more than 10 variables, of different types. Your suggestion of multiplexing doesn't work in this case.
I have something like this, where I want to bind ContentView.var1 to SettingsView.var1, for each of the var listed in SettingsView, and possibly to other views as well.
struct ContentView: View {
var body: some View {
VStack {
if var1 {
Text("Text")
}
}
SettingsView()
}
}
struct SettingsView: View {
@AppStorage("var1") private var var1 = false
@AppStorage("var2") private var var2 = true
@AppStorage("var3") private var var3 = false
@AppStorage("var4") private var var4 = MyType.Nested.value
@AppStorage("var5") private var var5: Double?
@AppStorage("var6") private var var6 = 0.0
@AppStorage("var7") private var var7 = 0.0
@AppStorage("var8") private var var8: String?
@AppStorage("var9") private var var9: Data?
@AppStorage("var10") private var var10 = true
@AppStorage("var11") private var var11 = 0
var body: some View {
Toggle("Var 1", isOn: $var1)
...
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: