Expandable List in SwiftUI (Simple way)

Create your own expandable List in SwiftUI in just a few minutes

Pavlos Simas
3 min readJul 5, 2023
Photo by Mia Baker on Unsplash

In SwiftUI there is a very simple way to create an expandable List in comparison with Swift which was a little bit more complicated.

SwiftUI List object is used instead of UITableView from UIKit. List object contains an initialiser in which you can declare that the list will include also some children. Also List object contains an arrow icon that handles the pointer automatically (pointing down when is opened, right when is closed).

So let’s go into the code directly. For this tutorial we will create a new project call ExpandableList and we will include everything in the ContentView file. You can do it in separate file if you want.

First of all we need to create a model for our expandable items. In our example we have some people and 3 group with different numbers of people. Here’s is our structure:

struct Person: Identifiable {
let id = UUID()
let name: String
let icon: String
var items: [Person]?

// people's names
static let paul = Person(name: "Paul", icon: "star")
static let john = Person(name: "John", icon: "star")
static let jeniffer = Person(name: "Jeniffer", icon: "star")
static let monica = Person(name: "Monica", icon…



Pavlos Simas

iOS Developer, with passion about Development, Marketing and Finance. Join Medium from the following link: https://simaspavlos.medium.com/membership