I am creating an alarm app using SwiftUI that allows a user to enter in how many hours of sleep they want which then calculates when the wake up time is from when they set the alarm but at the moment i am using a date picker to display the time like this:
EDIT: This is my code
@State private var hoursOfSleep = Date()
var body: some View {
HStack {
Text("Hours of Sleep").foregroundColor(Color.ui.textGray)
Spacer()
DatePicker("", selection: $hoursOfSleep, displayedComponents: .hourAndMinute)
.accentColor(Color.ui.textGray)
.frame(height: 20)
.labelsHidden()
}//: HStack
}
but this represents the actual time rather than the amount of hours and minutes so this would wake the user up at half past 7 rather than 7 hours and 30 min after setting the alarm.
Is there a better way for me to store the hours and minutes other than using a datepicker?
Any help would be much appreciated thank you.