Question: 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.

Answer: 
I had the same problem, and I solved it in the following way:

Note: I use **binding** to hide and/or show dynamically.

1 - Create Modifier

```swift
struct HiddenModifier: ViewModifier{
    var isHide:Binding<Bool>

    func body(content: Content) -> some View {
        if isHide.wrappedValue{
            content
                .hidden()
        }
        else{
            content
        }
    }
}

```

2 - Add Modifier to view:

```swift
extension View{
    func hiddenModifier(isHide:Binding<Bool>) -> some View{
        return self.modifier(HiddenModifier(isHide: isHide))
    }
}

```

3 - Use Modifier

```swift
struct CheckHiddenView: View {
    @State var hide:Bool = false

    var body: some View {
        VStack(spacing: 24){
            Text("Check Hidden")
                .font(.title)

            RoundedRectangle(cornerRadius: 20)
                .fill(Color.orange)
                .frame(width: 150, height: 150, alignment: .center)
                .hiddenModifier(hide: $hide)

            Button {
                withAnimation {
                    hide.toggle()
                }

            } label: {
                Text("Toggle")
            }
            .buttonStyle(.bordered)

        }
    }
}

```

**Test**

[![Check Swift hidden](https://i.stack.imgur.com/vECBW.gif)](https://i.stack.imgur.com/vECBW.gif)
The bad part of the above solution `.isHidden(true, remove: true)` is onAppear callback will not be called when `remove = true`.

`.opacity(isHidden ? 0 : 1)` is definitely the right way.