Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue using a ListView inside a FormView

Essentially I would like to add a section to my Form that is a dynamic list, why doesn’t this work inside a Form, any workaround?

        Form {
            Section("My List") {
                ForEach(list, id: \.self) { listItem in
                    Text(listItem.name)
                }
                .onAppear {
                    APICalls().getData(url: "https://test.com") { (info: [Couriers], _) in
                        self.list = info
                        if list == [] {
                            print("No Data")
                        } else {
                            
                        }
                    }
                }
                
            }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

move the .onAppear(...) outside the Form, like this (works for me)

var body: some View {
    Form {
        Section("My List") {
            ForEach(list, id: \.self) { listItem in
                Text(listItem.name)
            }
        }
    }
    .onAppear {
        APICalls().getData(url: "https://test.com") { (info: [Couriers], _) in
            self.list = info
            if list == [] {
                print("No Data")
            } else {
                
            }
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading