UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Create an expandable list out of two arrays

Forums > SwiftUI

I have these two arrays:

var customers = ["Example", "another"]
var projects = [["Website", "Example", "0:34:23"], ["Logo", "another", "0:58:56"], ["Big Project", "another", "5:23:56"]]

How can I make out of this an expandable list, which has in this case two categories "Example" and "another" and the children are the projects where the second item matches the customer.

The endresult should look like this:

3      

Not sure but this might be what you looking for

struct Data {
    var text: String
    var description: [Data]?
}

struct ContentView: View {
    let data = [
        Data(text: "Example", description: [Data(text: "Website"), Data(text: "Example"), Data(text: "0:34:23")]),
        Data(text: "Another", description: [Data(text: "Logo"), Data(text: "another"), Data(text: "0:58.56")]),
        Data(text: "Project", description: [Data(text: "Big Project"), Data(text: "another"), Data(text: "5:23:56")])

    ]

    var body: some View {
        List(data, id:\.text, children: \.description) { item in
            if item.description != nil {
                Text(item.text)
            } else {
                Text(item.text)
            }
        }
    }
}

Give this

or you can look at How to hide and reveal content using DisclosureGroup

3      

Ok thanks i will look at it tomorrow. (I live in Germany)

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.