ios – Find out how to routinely replace View Mannequin, when CoreData modifications in SwiftUI?

[ad_1]

Context

I’ve an App utilizing SwiftUI and CoreData. For displaying the Information and updating it routinely when modifications seem within the Mannequin, SwiftUI gives the @FetchRequest Property Wrapper, that can be utilized in Views.

Nonetheless, I want to have a ViewModel that manages the Information saved in CoreData and can be utilized by Views by means of the @Revealed Property Wrapper. However I’ve difficulties implementing an answer, that additionally updates routinely to modifications in CoreData.


Code

class SomeViewModel: ObservableObject {
    @Revealed var filteredEntities: [Entity]

    init() {
        // Load all Entities from CoreData, filter and assign them to filteredEntities.
        // Additionally be sure, that when CoreData modifications, the step above will get repeated.
    }
}

Questions

  • Is that this doable and was SwiftUI & MVVM designed for this?
  • How can I obtain the purpose described above?

[ad_2]

Leave a Reply