|
Hi everyone, I am on day 28 now and just finished typing up the project. Now I have a question for the challenge section from project 4 wrap up. it says I have to remove the button to calculate bedtime, therefore in order to show the bedtime, a function needs to be refreshed every time when a picker // stepper gets changed. and i can't seem to find a modifier that can do exactly that. 3 of the closest I found were
|
|
Hi Friends I have the same problem and i tried to solve this with Timer but i could do it because i dont know how can i use Selector ( @obj dont work). |
|
I don't understand your question. Each time one @State variable is changed in you view, your view is refreshed. During the refresh the line
is calculated so your view should alway show the good timeToSleep. There is no need to find a specific modifier. Doesn't the timeToSleep change when you change the wake up time, the time to sleep or the volume of coffee? |
|
hey sorry, only just saw your reply. the code I posted doesn't automatically update the ideal sleep time in Text. When I did this project, I hadn't learned about @ObservableOject, @published and @observedObject. It may work this way but I learned another way to do it as well which was way harder and I am still buffled how its done. But the solution is this in case you're interested.
|
|
You can make your original code work with these changes: Remove:
Change:
to:
Change:
to:
(And you don't need the The issue was that your |
|
|
|
|
|
OH my god ,you are so powerful,thank you ,roosterboy! Your solution is right,but I still don't understand the reason. |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.