To hide separators in SwiftUI we will use the modifier listRowSeparator and set its value to .hidden. Here you can see an example:
List {
ForEach(restaurants.indices, id: \.self) { index in
if(0...1).contains(index) {
FullImageRow(restaurant: restaurants[index])
}else{
BasicImageRow(restaurant: restaurants[index])
}
}
.listRowSeparator(.hidden)
}
.listStyle(.plain)
In XCode the result is as follows:
If you want more precise control over the line separators, you can use an alternative version of .listRowSeparator by specifying the edges parameter. For example, if you want to keep the separator only at the top of the list view, you can write the code like this:
.listRowSeparator(.hidden, edges: .bottom)