Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import SwiftUI
struct ContentView: View {
@State var value1 = Double()
@State var value2 = Double()
@State var total = Double()
func addValues() {
total = value1 + value2
}
var body: some View {
VStack {
Slider(value: $value1, in: 0...100,
minimumValueLabel: Text("0"),
maximumValueLabel: Text("100")) {
Text("Value 1")
}
.onChange(of: value1) {
_ in addValues()
}
Slider(value: $value2, in: 0...100,
minimumValueLabel: Text("0"),
maximumValueLabel: Text("100")) {
Text("Value 2")
}
.onChange(of: value2) {
_ in addValues()
}
Text("Total: \(total)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment