ios – SwiftUI move Views from dad or mum to little one


I need to have a customized SwiftUI View which renders & types Views handed to it from its dad or mum.

I attempted with this code:

struct CustomView<Content material: View>: View {
    let views: [Content]
    
    init(_ views: [Content]) {
        self.views = views
    }
    
    public var physique: some View {
        VStack {
            ForEach(views.indices, id: .self) { index in
                let view = views[index]
                view
                    .padding(.main, 15)
            }
        }
    }
}
struct OuterView: View {
    @State var choice: String
    
    var physique: some View {
        CustomView([
            HStack(content: {
                Text("details")
                Spacer()
                Image(systemName: "chevron.right")
            }),
            HStack(content: {
                Text("attend")
                Spacer()
                Picker(selection: $selection) {
                    Text("full")
                } label: {
                    EmptyView()
                }
            })
        ])
    }
    
}

I get the next error: “Can’t convert worth of sort ‘Picker<EmptyView, String, Textual content>’ to anticipated argument sort ‘Picture'”

Plainly the code expects each View to take the identical type.

How can I modify this code so that every view handed by could be distinctive?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles