I'd like to filter an array of object if the todoStatus === true and then return the count but I am unsure of how to go about it,I can already get the count of the entire array, but I'm not sure how to filter it down.
Here is what the structure looks like:
class ToDo: ObservableObject, Identifiable {
var id: String = UUID().uuidString
@Published var todoName: String = ""
@Published var todoStatus: Bool = false
init (todoName: String, todoStatus: Bool) {
self.todoName = todoName
self.todoStatus = todoStatus
}
}
class AppState: ObservableObject {
@Published var todos: [ToDo] = []
init(_ todos: [ToDo]) {
self.todos = todos
}
}
struct ContentView: View {
var name = "Leander"
@ObservedObject var state: AppState = AppState([
ToDo(todoName: "Wash the Dogs", todoStatus: true),
ToDo(todoName: "Wash the Dogs", todoStatus: false),
ToDo(todoName: "Wash the Dogs", todoStatus: true),
ToDo(todoName: "Wash the Dogs", todoStatus: false),
ToDo(todoName: "Wash the Dogs", todoStatus: true),
ToDo(todoName: "Wash the Dogs", todoStatus: false),
])
and how I'm accessing the count
Text("\($state.todos.count)")