SwiftUI: how to get rid of top and bottom separators on lists

Viewed 57

I'm working with Lists in SwiftUI, and noticed that when I have only one row, the separators still appear on the top and bottom:

enter image description here

Similarly, for Lists with multiple rows, these separators still appear on the top and bottom. How can I remove the separator at the very top and very bottom of a List, while keeping separators between middle rows?

1 Answers

You can just hide separators using modifier (iOS 15+)

List {
    ForEach(garage.cars) { car in
        Text(car.model)
            .listRowSeparator(.hidden)    // << this !!
    }
}
Related