As default SwiftUI List stack the row by time, which results in the most recently created row is at the end of the list.
Instead I want most recently created row to be at upfront, the first row of the list.
Is there anyway to achieve this?
You can reverse the List so the most recent data is stored on top.
Here is an example with a button so you can add elements to the List and test it out.
struct ContentView: View {
@State var dataStore = [0, 1, 2]
var body: some View {
VStack {
List(dataStore.reversed(), id: \.self) { data in
Text(String(data))
}
Button(action: {
self.dataStore += [self.dataStore.count]
}) {
Text("Insert to list")
}
}.listStyle(GroupedListStyle())
}
}