import SwiftUI
class DataClass :ObservableObject {
@Published var number:Double = 0.0
}
struct DataStruct {
var number:Double = 0.0
}
struct ContentView: View {
@State var number:Double = 0.0
@ObservedObject var dataClass = DataClass()
@State var dataStruct = DataStruct()
var body: some View {
VStack {
VStack {
Text("class:\(dataClass.number)").padding()
Slider(value: $dataClass.number, in:0.0...10.0)
}
VStack {
Text("struct:\(dataStruct.number)").padding()
Slider(value: $dataStruct.number, in:0.0...10.0)
}
VStack {
Text("normal:\(number)").padding()
Slider(value: $number, in:0.0...10.0)
}
}
}
}
|