-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
hello,
first let me prephrase that i'm a Swift newbie so it might just be a misunderstanding and skill issue
i'm trying to centralize my app state into its own class, so i can provide methods to mutate the data all over my app
tried to do something like below, but the app does not respond to the buttons input
am i doing something wrong or is it not possible / intended cause bad practice?
@State var appState = AppState()
var body: some View {
content
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.border(.rounded)
}
private var content: some View {
VStack {
ForEach(appState.getTodoList(), id: \.id) { todo in
HStack {
Text(" [\(todo.completed ? "x" : " ")] \(todo.id) - \(todo.title)")
Spacer()
Button("Complete") {
if let index = appState.getTodoList().firstIndex(where: { $0.id == todo.id }) {
appState.toggleTodoCompletion(at: index)
}
}
Button("Remove") {
if let index = appState.getTodoList().firstIndex(where: { $0.id == todo.id }) {
appState.removeTodo(at: index)
}
}
}
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels