Created
June 27, 2020 12:54
-
-
Save shaundon/a0534776c33a20d7b200743801942f09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
class MyModel: ObservableObject { | |
@Published var segmentedControlValue: Int = 0 { | |
didSet { | |
self.accumulator += 1 | |
print("segmentedControlValue set to \(self.segmentedControlValue)") | |
} | |
} | |
@Published var accumulator: Int = 0 | |
} | |
struct TestView: View { | |
@ObservedObject var model = MyModel() | |
var body: some View { | |
VStack { | |
Text("Pressed \(model.accumulator) times") | |
Picker(selection: $model.segmentedControlValue, label: Text("Choose one")) { | |
Text("0").tag(0) | |
Text("1").tag(1) | |
}.pickerStyle(SegmentedPickerStyle()) | |
} | |
} | |
} | |
struct TestView_Previews: PreviewProvider { | |
static var previews: some View { | |
TestView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment