Here I have created a observable object, which I added in environment object. On list row click I need to update some values of my environment object before navigating on DetailView. Simply I want to show detail of object based on row selection.
Here is the code I tried:
class MyModel:ObservableObject
{
var selectDate: String
var duration: String
var selectProject: String
init(dateStr: String, durationStr: String, projectName: String) {
self.selectDate = dateStr
self.duration = durationStr
self.selectProject = projectName
}
}
struct ContentView: View {
@EnvironmentObject var model: MyModel
@Environment (\.colorScheme) var colorScheme:ColorScheme
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@ObservedObject var viewModel = TimesheetViewModel()
var body: some View {
List {
ForEach(self.viewModel.tasksArr, id:\.id) { taskObj in
NavigationLink(destination: DetailView()) { >need to update **model** before navigating Detail View
TimeSheetRowView(taskObj:rowElement)
}
}
}
Is there any other way to perform same task? Help me out in this