'How to dynamically set date from Core data in a textfield in SwiftUI

I want to try to update a diary and when I click on the datePicker and changes date, the textfield date does not update instantly. It updates when I click on update button and go to the home view and come back. Please help if could.

This is the Home View of my app.

The is when I click on the any record(update view)

This is what I've tried. @State var diary: MyDiary_Entity. diary is my object of the entity.

enter image description here



Solution 1:[1]

If you use @ObservedObject var diary: Diary then body will be called when it changes.

By the way your date formatting and binding supplied to DatePicker have mistakes. And I think you are doing too much in that View struct.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 malhal