UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Day 28 - Project 4, part 3

Forums > 100 Days of SwiftUI

Hi again guys.

I solved the challenge but I searched the docs and find a different solution using stuff that Paul didn't teach yet.

Used the .onChange() modifier to call the method everytime some action change my @State's.

 DatePicker("Please enter a time",
                               selection: $wakeUp,
                               displayedComponents: .hourAndMinute)
                        .datePickerStyle(WheelDatePickerStyle())
                        .labelsHidden()
                        .onChange(of: wakeUp, perform: { value in
                            calculateBedTime()
                        })

But I really want to know how to solve that using the material that I learned until this lesson, as Paul says it's all we need to solve.

3      

Well done. You will find that some of the challenges are not covered by the tutorial but that the point is to find outa way of doing it with search the web and stackoverflow etc.

4      

Wow Now I got it, thanks.

3      

I also ended up using .onChange on all three of the @State variables (sleepAmount, coffeeAmount,wakeUp) so that it will update with every user input but it feels computationally tasking to recalculate the result after every single variable change.

I am guessing this task was given to teach us how to do a such setup rather than because it makes sense to do it this way? Or there is a much more better way of doing this and I can't see it.

3      

Hacking with Swift is sponsored by RevenueCat

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.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.