|
I'm trying to figure out BetterRest app challenge #3. Goal is to do away with the calculate button and have the app always display the recommended bedtime. My solution was to add an action to the cups per day Picker that calls the calculate bedtime function. When I run the app and change the cups of coffee from the default the action to call the calculate bedtime function doesn't work. Any assistance would be appreciated.
|
|
|
|
Thanks for the tip. I looked up the method in the Swift documentation and reviewed example there. I thought I could attach the method to the app Form but get an error message that value of type Form has no member 'onChange(of)'. I tried attaching to all the views, i.e., Section, Form and Navigation with the same result. Surely I'm doing something wrong but not sure what... |
|
Try to move most of the calculateBedTime function into a computed property and then pass that along into a Text view somewhere in your app. Think about it this way... You have @State variables. Whenever ANY @State variable is changed in your view, the view recognizes that change and as a result it destroys the view and re-creates it. This means that any computed properties inside the view also get re-calcuted! |
|
|
|
|
|
So...I attached the method again to my new Section with the text required by the challenge and got no error this time. The onChange did the trick. Not sure why I was getting the errors before exactly. Will have to look into that. Thanks for your help. |
SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.
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.