I want to make a meditation app. There are two variables set by the user. After counting up from 1 to one variable, I want to count up the number from 1 to the other variable.
@AppStorage("exhaleTimer_Value") var exhaleTimerValue = 10
@AppStorage("inhaleTimer_Value") var inhaleTimerValue = 5
// Count up every second
timerHandler = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
// Called when the timer is executed
countdownTimer()
}
func countdownTimer() {
count += 1
I want it to look like this.
func breath() {
// Count up to the inhalation time set by the user
if count <= inhaleTimerValue {
// Count up to the time to inhale
} else {
// Since count exceeds the time set by the user, set it to 0.
count = 0
}
// This time, it counts up to the time you set to exhale.
if count <= exhaleTimerValue {
// Count up to the time to exhale
} else {
// Since count exceeds the time set by the user, set it to 0.
count = 0
}
// Count up to the time to inhale
}
What I want to know the most here is how to count up to one variable and then to another variable. If possible, I would be grateful if you could tell me about the process of repeating it.
I would be happy if you could answer.