1

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?

1 Answer 1

2

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())
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.