I'm trying to conditionally hide a DatePicker
in SwiftUI. However, I'm having any issue with mismatched types:
var datePicker = DatePicker($datePickerDate)
if self.showDatePicker {
datePicker = datePicker.hidden()
}
In this case, datePicker
is a DatePicker<EmptyView>
type but datePicker.hidden()
is a _ModifiedContent<DatePicker<EmptyView>, _HiddenModifier>
. So I cannot assign datePicker.hidden()
to datePicker
. I've tried variations of this and can't seem to find a way that works. Any ideas?
UPDATE
You can unwrap the _ModifiedContent
type to get the underlying type using it's content
property. However, this doesn't solve the underlying issue. The content
property appears to just be the original, unmodified date picker.