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

SOLVED: Day 54 Bookworm - Picker: the selection "" is invalid and does not have an associated tag, this will give undefined results warning

Forums > 100 Days of SwiftUI

@orkun  

I got the "Picker: the selection "" is invalid and does not have an associated tag, this will give undefined results" warning in the console when I run the application and navigated to the AddBookView.

@State private var rating = 3

Section {
    TextEditor(text: $review)
    Picker("Rating", selection: $rating) {
        ForEach(0..<6) { rating in
            Text("\(rating)")
        }
    }
} header: {
    Text("Write a review")
}

There was no warning when Paul navigated to AddBookView. Why do I get this warning?

2      

Add id: \.self to ForEach should make the warning go away.

ForEach(0..<6, id: \.self) { rating in
    Text("\(rating)")
}

2      

@orkun  

Unfortunately it still appears.

2      

Hi @orkun, I was getting the same warning but it was the picker for the genre, check to see if your genre state var is set to " ", if it is just add Fantasy to it.

2      

@orkun  

Thank you! I completely forgot that second picker.

2      

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.