Created
October 7, 2019 15:41
-
-
Save tgunr/afe7329038427d4190c7596a297f8595 to your computer and use it in GitHub Desktop.
Initialize Subview
This file contains 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
... | |
@State var medication: Medication | |
... | |
TakeView(hour: $medication.interval) |
This file contains 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
struct TakeView: View { | |
@Binding var hour: Int | |
@State private var hourString: String = "" | |
let range = 1...12 | |
var body: some View { | |
let binding = Binding<Int>( | |
get: { self.hour }, | |
set: { | |
self.hour = $0 | |
self.hourString = String(self.hour) | |
}) | |
return Stepper(value: binding, in: range) { | |
if hour > 1 { | |
Text(verbatim: "\(hourString) hours") | |
} else { | |
Text(verbatim: "hour") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment