I'm relatively new to SwiftUI and I want to update a wave function (which represents how full the coffee is) by changing the variable caffeineContent with a Button.
The value is changing if I print it but the Content-View stays the same and isn't updating. I thought about forcing to update the UI, but this solution does not seem right to me.
Info:
caffeineContent = 50 --> Coffee is full
caffeineContent = 0 --> Coffee is empty
var caffeineContent: Int = 10
struct ContentView: View {
@State private var showModal = false
@State private var percent = caffeineContent
var body: some View {
ZStack {
Color(red: 0.5, green: 0.4, blue: 0.35).ignoresSafeArea()
[…]
CircleWaveView(percent: Int(caffeineContent)).padding(EdgeInsets(top: 90, leading: 65, bottom: 100, trailing: 79))
}
[…]
Button(action: {
caffeineContent = caffeineContent+5
print(caffeineContent)
}, label: {
Text("Add caffeine content").font(.largeTitle)
[…]