Thanks for the reply! Here's my code for updating the data
func autosave(note: Note) {
let updateTitle = self.title
let updateBodyText = self.bodyText
let updateDateModified = Date()
viewContext.performAndWait {
note.title = updateTitle
note.bodyText = updateBodyText
note.dateModified = updateDateModified
do {
try viewContext.save()
print("Note saved!")
} catch {
print(error.localizedDescription)
}
}
}
And here's where I fetched the data
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(entity: Note.entity(), sortDescriptors: [NSSortDescriptor(key: "dateModified", ascending: false)], predicate: nil)
var updatedNote: FetchedResults<Note>
Which I passed into the other view, which treats the data like a regular variable (code below is in the second view)
struct NoteMenuItem: View {
var note: FetchedResults<Note>.Element
var body: some View {
HStack {
VStack(alignment: .leading) {
Text(note.title ?? "")
.font(.headline)
.padding(.bottom, 1)
Text(note.bodyText ?? "")
.font(.subheadline)
.lineLimit(2)
}
Spacer()
}
.padding(.leading, 25)
.padding(.trailing, 25)
.padding(.top, 10)
.padding(.bottom, 10)
}
}
I don't think I explicitly reloaded the table, since I assumed it does so itself? Though the data still updates in one of the views correctly.