Swift newbie right here. I’m attempting to create a reusable element that merely renders both a stuffed or empty systemImage circle primarily based on a price saved in state. I’ve put collectively a replica instance beneath. Proper now it solely seems to be updating the worth in state (in formData), however the UI would not appear to be updating (the circle is just not filling up). I’ve a sense the Picture and Textual content elements are set as much as react to state modifications, however I am unsure methods to repair from there. Thanks prematurely!

import SwiftUI

struct Check: View {
    @ObservedObject var formData = FormData()

    var physique: some View {
        VStack {
            Textual content("Efficiency: (String(formData.targets.efficiency))")
            Toggle(isOn: Binding(
                get: { formData.targets.efficiency },
                set: { formData.targets.efficiency = $0 }
            )) {
                Textual content("Efficiency")
            }
            ChildWrapper(isPerformanceEnabled: $formData.targets.efficiency)
        }
    }
}

struct ChildWrapper: View {
    @Binding var isPerformanceEnabled: Bool

    var physique: some View {
        VStack {
            Picture(systemName: isPerformanceEnabled ? "circle.fill" : "circle")
                .font(.system(dimension: 50))
                .foregroundColor(isPerformanceEnabled ? .inexperienced : .crimson)
                .onTapGesture {
                    isPerformanceEnabled.toggle()
                }
            Textual content(isPerformanceEnabled ? "Enabled" : "Disabled")
        }
    }
}

struct Test_Previews: PreviewProvider {
    static var previews: some View {
        Check()
    }
}

3