In my SwiftUI, I have the following:
struct PersonalDetailsView: View {
// The profileStore manages user related data
@EnvironmentObject var profileStore: ProfileStore
var body: some View {
DatePicker(selection: $profileStore.observedPerson.birthday,
in: ...Date(),
displayedComponents: [.date]) {
Text("Birthday")
}
Picker("Weight", selection: $profileStore.observedPerson.weight) {
ForEach(0 ..< 300) {
Text("\($0) kg").foregroundColor(.gray)
}
}
}
}
weight
and birthday
are both optionals. In the normal Picker I don't get any error, but in the DatePicker I get the following:
Cannot convert value of type 'Binding< Date? >' to expected argument type 'Binding< Date >'
How can I fix this? If you need further information about profileStore
or observedPerson
, just comment.