Post

Replies

Boosts

Views

Activity

Sort Results of SwiftUI FirebaseQuery()
Hey There. Any idea how to sort this in SwiftUI? // // ToDoListItemsView.swift // ToDoList // // Created by Neo on 9/14/23. // import FirebaseFirestoreSwift import SwiftUI struct ToDoListView: View { @StateObject var viewModel = ToDoListViewViewModel() @FirestoreQuery var items: [ToDoListItem] private let userId: String init(userId: String) { self.userId = userId self._items = FirestoreQuery( collectionPath: "users/\(self.userId)/todos" ) } var body: some View { NavigationView{ VStack { List(items) { item in ToDoListItemView(item:item) .swipeActions { Button { viewModel.delete(id: item.id) } label: { Text("Delete") /// fix this later } .tint(Color.red) } } .listStyle(PlainListStyle()) } .navigationTitle("To Do List") .toolbar { Button { viewModel.showingNewItemView = true } label: { Image(systemName:"plus") } } .sheet(isPresented: $viewModel.showingNewItemView){ NewItemView(newItemPresented: $viewModel.showingNewItemView) } } } } struct ToDoListView_Previews: PreviewProvider { static var previews: some View { ToDoListView(userId: "blahblahblahblahblah") } } Here is the model: // // ToDoListItem.swift // ToDoList // // Created by Neo on 9/14/23. // import Foundation struct ToDoListItem: Codable, Identifiable { let id: String let title: String let dueDate: TimeInterval // Add Priority Later let createdDate: TimeInterval var isDone: Bool mutating func setDone(_ state: Bool){ isDone = state } } I've googled for hours and cannot sort the final list by "dueDate"....
1
0
354
Sep ’23