TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Converting List with children to ForEach

Forums > SwiftUI

Hello, I found following tutorial to create a List with autoexpanding items: https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-expanding-lists

and I'm trying to convert it to ForEach. I learned that the main difference between List and ForEach is that the latter should be used for more complex view hierarchy but I struggle to write the right code in this case. It seems that ForEach is missing this functionality and I need to use DisclosureView?

This is the original code:

    var body: some View {
        List(items, children: \.items) { row in
            HStack {
                Image(systemName: row.icon)
                Text(row.name)
            }
        }
    }

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.