WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.