SwiftUi finally introduced tables and i would like to print different tables from the same data by just filtering it.
For example i would like to populate the table only with adult persons
struct Person: Identifiable {
let givenName: String
let familyName: String
let age: Int
let id = UUID()
}
private var people = [
Person(givenName: "Juan", familyName: "Chavez", age: 4),
Person(givenName: "Mei", familyName: "Chen", age: 18),
Person(givenName: "Tom", familyName: "Clark", age: 17),
Person(givenName: "Gita", familyName: "Kumar", age: 60),
]
var body: some View {
Table(people "where people.age>18") { //yes this is pseudocode ofc
TableColumn("Given Name", value: \.givenName)
TableColumn("Family Name", value: \.familyName)
}
}
I know i could create another array derived from the main one by just populating it with people.age>18 but i need several filterings, i have a lot of data and i would like a solution smarter than just creating several other array
Any idea ?