Post

Replies

Boosts

Views

Activity

Reply to Need suggestions on publisher autosave solutions
@OOPer, the behavior of TextEditor is expected, but as you see, I created a @State variable to store the input of Users so I need to update the instance of EnvironmentObject with the @State variable . I tried to put the instance of EnvironmentObject directly into the TextEditor but it cannot compile with an error: Failed to produce diagnostic for expression; please file a bug report swift TextEditor(text: $UserData.NoteList[label ?? ""][id ?? 0].title ?? $title)                     .font(.title2)                     .padding(.top)                     .padding(.horizontal)                     .frame(height: 50, alignment: .center)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21
Reply to Need suggestions on publisher autosave solutions
I should have put more context here. Thanks for the suggestions. I tried .onChange modifier: swift .onChange(of: content, perform: { value in                         UserData.editPost(label: label!, id: id!, data: SingleNote(updateDate: Date(), title: title, body: value))                     }) It works to some extent if I type in something, it should update the instance of EnvironmentObject. But what is weird is, this editing view is a child view of a navigation link. Whenever I type in something, the changes have been made to the EnvironmentObject and the parent view gets refreshed. So the current view dismisses as a result and I was pushed to the parent navigation view. Intuitively, every time I type in something with the onChange solution, the changes happen and I get pushed to the parent view since the model in the parent view gets refreshed.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21