|
Challenge 3 of BetterRest (day 28) requires us to make the idea of sleep time always show and update. I don't think anything we already know is enough to solve this so I had to google it and find out that I should use |
|
Hi @Shawn0919!
Why is that? You can create computed property for that and use it. So initially you can have default values. And then once you change them your computed property will update the view for your sleep time.
and in view you can use it something like this.
|
|
Thank you @ygeras for your response! That's actually what i did in the first place, but I keep calculateBedTime as a function as what's in the tutorial, but by adding a return value, then calling it in that Text view, then weirdly, the code will compile and there are no errors, but the Text view will show nothing. Then just now I just tried yours way to make it a variable, then its still the same thing, no error but nothing show up. Here is my code piece:
Then in the body:
|
|
But wait, in your If you put that alert in your view that it will work:
and then you will have to watch it change etc etc etc...
and then you have to trigger |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.