TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Project 4 Challenge 2 Picker solution

Forums > 100 Days of SwiftUI

I believe Paul's final Picker in his "Solution to BetterRest" video has a mistake. It references the 2nd item in the ForEach loop as if it was the first one...

I managed to solve it by adding .tag($0) on the end of the Text item. Not sure exactly why that works, but it seems to!

Section("Daily coffee intake") {
    Picker("Number of cups" ,selection: $coffeeAmount) {
        ForEach(1..<21) {
            Text(String($0)).tag($0))
        }
    }
}

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!

Reply to this topic…

You need to create an account or log in to reply.

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.