How can I fix the reason why the warning appears?

struct ContentView: View {

    @State private var selectedDate: Date = Date()

    var body: some View {
        Form {
            DatePicker("Date", selection: $selectedDate, displayedComponents: .date)
        }
    }
}
1

There are 1 best solutions below

2
On BEST ANSWER

A workaround solution would be to use a List View instead of a Form. It all depends on what you want to put in your Form. For demonstration purpose, using a List, your code would look like this:

struct ContentView: View {

    @State private var selectedDate: Date = Date()

    var body: some View {
        List {
            DatePicker("Date", selection: $selectedDate, displayedComponents: .date)
        }
        .listStyle(InsetGroupedListStyle())
    }
}

The above gives the same visual effect (UI) as using a List, and no warning is shown.

Because everything is working correctly with your Form, I don't really see the need to change your Form to a List just to avoid the logs.