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

[Solved] ForEach loop in picker, message in Xcode console

Forums > 100 Days of SwiftUI

I just complete Better rest challenge.

I put daily cup in a icker with this code

Section (header: Text("Daily coffe intake")) {
                    Picker(selection: $coffeeSelection,
                           label: Text("Select coffe intake")) {
                            ForEach(1 ..< 20) {
                                if $0 == 1 {
                                    Text("1 cup")
                                } else {
                                    Text("\($0) cups")
                                }
                            }
                    }
                    .labelsHidden()
                    .datePickerStyle(WheelDatePickerStyle())
                }

Everything work fine but I have a strange message in Xcode console :

ForEach(:content:) should only be used for constant data. Instead conform data to Identifiable or use ForEach(:id:content:) and provide an explicit id!

What doest it mean?

Full code is on GitHub

Warm regards seb

3      

You using .datePickerStyle(WheelDatePickerStyle()) when should use .pickerStyle(WheelPickerStyle()). I do not know if solves the warning.

4      

Thank you @NigelGee it solve the problem.

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.