Post

Replies

Boosts

Views

Activity

List with Bindings from ObservedObject
Hi,I'm trying to build a really simple Todo-List App to get started with SwiftUI.I decided on a store object that acts as my single source of truth for Todo entries, it's really the most basic example one can imagine.struct Todo: Identifiable { var id = UUID() var title: String var isDone = false } class TodoStore: ObservableObject { @Published var todos: [Todo] = [] }I want to display the Todo-Entries in a List, but in seperate ListRow views that each have a Binding on a Todo value.struct ListRow: View { @Binding var todo: Todo var body: some View { Button(action: { self.todo.isDone.toggle() }) { Text(todo.title) } } }So now, when I try to setup the actual List, I get an error:Cannot convert value of type '(Binding<Todo>) -> ListRow' to expected argument type '(_) -> _'struct ContentView: View { @ObservedObject var todoStore = TodoStore() var body: some View { List(todoStore.todos, id: \.self) { todo in ListRow(todo: todo) } } }What am I missing here?
4
0
7.9k
Sep ’19