79085867

Date: 2024-10-14 10:59:30
Score: 2
Natty:
Report link

Yes @Andrei G. is right .. you need to use @state variable as structs are value types ..

Xcode example..

struct SwiftUIDemo: View {
    @State var tapCount = 0

    var body: some View {
        Button("Tap Count: \(tapCount)") {
            self.incrementCount()
        
        }
    }

    func incrementCount() {
        self.tapCount += 1
        print(tapCount)
    }
}
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • User mentioned (1): @Andrei
  • User mentioned (0): @state
  • Low reputation (0.5):
Posted by: RSRoy