Group Multiple View Modifiers in SwiftUI

Quite often we write the same view modifiers multiple times here and there in code. It's not that bad but sometimes we want to follow DRY principle:

List {
    Section {
        rowsToday()
            .listRowBackground(Color.clear)
            .listRowSeparator(.hidden)
    }

    Section {
        rowsTomorrow()
            .listRowBackground(Color.clear)
            .listRowSeparator(.hidden)
    }
}

Luckily, there is a way to squash them into one line! One more step: make a View class extension.

struct ResetListRow: ViewModifier {
    func body(content: Content) -> some View {
        content
            .listRowBackground(Color.clear)
            .listRowSeparator(.hidden)
    }
}

extension View {
    func resetListRow() -> some View {
        modifier(ResetListRow())
    }
}

And that's how the code looks like after update:

List {
    Section {
        rowsToday().resetListRow()
    } 
    Section {
        rowsTomorrow().resetListRow()
    }
}