[ad_1]
I am fairly new to SwiftUI, apologies prematurely if this a poor query, I’ve researched and I can not appear to seek out the reply. In my ContentView I’ve a few stateful variables that retailer values for my slider in a sub view (CustomTextFieldAndSlider) beneath that.
How will we retailer these stateful variables with out having to move them into the @fundamental
app struct myAppApp.swift? Once I do move them into the @fundamental App struct I’ve to hardcode them as .fixed / textual content parameters which does not permit the stateful performance desired.
@fundamental MyAppApp.swift
import SwiftUI
@fundamental
struct Foo: App {
var physique: some Scene {
WindowGroup {
ContentView(homePriceText: "")
}
}
}
ContentView
struct ContentView: View {
@State var homePriceText: String
@State var homePrice: Double = 0
var physique: some View {
ZStack{
Coloration.grey.opacity(0.1)
VStack(alignment: .main) {
CustomTextFieldAndSlider(labelText: "foo", placeholder: "foo", showLeadingIcon: true, leadingIcon: "dollarsign.circle", textBinding: $homePriceText, sliderBinding: $homePrice)
}
.padding()
}
.ignoresSafeArea()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(homePriceText: "0", homePrice: 200000)
}
}
[ad_2]
