I’m attempting to follow the structure in the ListSwiftUI example at
https://github.com/realm/realm-cocoa/blob/master/examples/ios/swift/ListSwiftU
that Jason demoed in the webinar at
It is my understanding that I need both List
and ForEach
in order to use the .onMove
and .onDelete
magic that Jason demoed in the webinar that showed this stuff, but I cannot figure out how to actually show the data when wrapping the ForEach in a List.
My Situation
In my view I am using
@ObservedRealmObject var huntlet: Huntlet
My list looks like
Text("Huntlet is called\(huntlet.title)")
Text("Huntlet has \(huntlet.tasks.count) task(s)")
List {
ForEach(huntlet.tasks) { task in
TaskListEditRowView(task: task)
}
}
// Also, just for reference
struct TaskListEditRowView: View {
@ObservedRealmObject var task: Task
var body: some View {
TextField("Task Name", text: $task.title)
.foregroundColor(Color("navy"))
}
}
Note: The first two Text()
views in this struct are just to verify that the data is getting there.
This code is producing this result:
When I take the list out and just use ForEach, it loads the data:
// List {
ForEach(huntlet.tasks) { task in
TaskListEditRowView(task: task)
}
// }
produces:
Any ideas?