I'm passing an object of a coredata model(ItemModel) using enums like this
.sheet(item: $activeSheet, onDismiss: { self.activeSheet = nil }) { item in
switch item {
case .newDoc:
NewDocumentView(ref: nil).environment(\.managedObjectContext, context)
case .detailFolder(let data):
DetailedFolderView(item: data, dirName: data.wrappedName, updater: viewUpdater).environment(\.managedObjectContext, context)
case .detailDoc(let file):
DetailDocumentView(item: file, fileName: file.wrappedItemName)
.environment(\.managedObjectContext, context)
}
}
but while i try to update the ItemModel
object in the DetailDocumentView
using the managed object context after saving and dismissing the view the parent view isnt updated, the view updates only after restarting the app
Can anyone suggest a way to update the parent view after updating the object of the coredata model(ItemModel
) being passed in DetailDocumentView
. Any suggestions are welcome :)
Been stuck on this issue for hours, tried using observable objects, tried using a publisher when context is updated, but noting has worked so far :(
Heres a reference of the code used when tapped on a file to present DetailDocumentView
/// creates a grid to display data
/// - Parameters:
/// - geometry: setup dimension for the grid view
/// - folders: files required
/// - Returns: returns a grid
private func gridView(_ geometry: GeometryProxy, files: FetchedResults<ItemModel>) -> some View {
QGrid(files,
columns: 2,
columnsInLandscape: 0,
vSpacing: 20,
hSpacing: 35,
vPadding: 10,
hPadding: 10,
isScrollable: false,
showScrollIndicators: false) { file in
FileItemView(item: file)
.environment(\.managedObjectContext, context)
.onTapGesture {
self.activeSheet = .detailDoc(file: file)
}
}
}