LAST CHANCE: Save 50% on all my Swift books and bundles! >>

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?

3      

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

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

3      

@orkun  

Unfortunately it still appears.

3      

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.

3      

@orkun  

Thank you! I completely forgot that second picker.

3      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

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.