TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

presenting views using associated value of enum case

Forums > SwiftUI

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)
                }
        }
    }

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.