Hello!
I'm not able to find the correct way to reflect data change in my app. I'm probably mentally stuck, so a new and fresh approach could help.
I have this structure that represents an entry in my view hierarchy.
struct WeekdayEntry: Identifiable, Equatable, Hashable {
let id: UUID = UUID()
let date: Date
var event: Event?
}
This is the code of my view (of course it's simplified):
@State private var dataSource: [WeekdayEntry] = [] // this is filled in another part of the code, so it's never empty
@State private var isCreationMode: Bool = false
ScrollView {
ForEach(dataSource.sorted { $0.date < $1.date }) { entry in
WeekdayRowView(entry: entry, isCreationMode: $isCreationMode)
}
}
This is the WeekdayRowView
:
struct WeekdayRowView: View {
@State var entry: WeekdayEntry
.
.
.
}
When I enable creation mode, I'm able to change the data. Then, when I finish, I'd like to have those data changes reflected in my list, but this does not happen. Surely I need a @Binding
inside the WeekdayRowView
. But, how can the event
reference be updated within the WeekendEntry
object?
This is the visual representation of the above code. The WeekdayRowView
is the one in the list below the calendar, with the grey date.