Swiftui 将绑定指定给容器视图

Swiftui 将绑定指定给容器视图,swiftui,Swiftui,我在为MyContainer分配绑定值时遇到了问题,因为我得到了“无法将“binding”类型的值分配给“Bool”类型”,并且无论我探索了多少迭代,都无法通过它 我有一个TestingContainer结构,我在其中声明了我在按钮->中使用的showContainer,我希望该值能够到达MyContainer struct TestingContainer: View { @State private var showContainer = false var bod

我在为MyContainer分配绑定值时遇到了问题,因为我得到了“无法将“binding”类型的值分配给“Bool”类型”,并且无论我探索了多少迭代,都无法通过它

我有一个
TestingContainer
结构,我在其中声明了我在按钮->中使用的
showContainer
,我希望该值能够到达
MyContainer

struct TestingContainer: View {
    @State private var showContainer = false
    
    var body: some View {
        VStack {
            MyContainer(show: $showContainer) {
                VStack {
                    ForEach(0 ..< 5) { item in
                        Text("Hi!")
                    }
                }
            }
            if showContainer == false {
                Button(action: {showContainer = true}, label: {
                    Text("Show Container")
                })
            }
        }
    }
}

你能帮我找出我的错误吗


谢谢大家!

应该是这样的

init(show: Binding<Bool>, @ViewBuilder content: () -> Content) {
        self.content = content()
        self._showContainer = show
    }
init(show: Binding<Bool>, @ViewBuilder content: () -> Content) {
        self.content = content()
        self._showContainer = show
    }
Color.black.opacity(self.showContainer ? 0.1 : 0).edgesIgnoringSafeArea(.all)