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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
@AppStorage("exhaleTimer_Value") var exhaleTimerValue = 10
I want to display this variable 10 in order up to 1, 2, 3 ...
How can I do this?
please answer.
There are three times that the user sets.
Time to meditate.
Time to take a breath.
Time to exhale.
@AppStorage("timer_value") var timerValue = 600
@AppStorage("exhaleTimer_Value") var exhaleTimerValue = 15
@AppStorage("inhaleTimer_Value") var inhaleTimerValue = 3
In the time to meditate, I want to repeat the time to inhale and the time to exhale.
How can I do that?
Thank you for your answer.
Originally there was a picker to choose a few seconds.
@AppStorage("timer_Value") var timerValue = 10
I want to treat this as 10 minutes and 600 seconds instead of 10 seconds.
I tried various things for that, but I get an error. Why are you getting these errors? What do I not know? What should i do? I would like you to tell me.
1
@State var trueTimerValue = timerValue * 60
↓
// Error displayed
Cannot use instance member 'timerValue' within property initializer; property initializers run before 'self' is available
2
I copied the code that was in the book var area: Int { sideLength * sideLength }
↓
@State var trueTimerValue: Int { timerValue * 60 }
// Error displayed
Property wrapper cannot be applied to a computed property
I would appreciate it if you could answer.