hi,
i'd recommend looking at 2 options.
(1) instead of using a @FetchRequest
in a View and then handing that data off to a data object (a class that is an ObservableObject
), consider using an NSFetchedResultsController
(FRC) in the data object instead. when you create the FRC, and whenever the FRC kicks in response to a change in Core Data, use what comes back to reset all the @Published
properties of the data object (and any view that tracks the data object as an @ObservedObject
will get the update message).
(2) instead of having a data object that's more-or-less global, keep any necessary @FetchRequest
in a View, and implement a local function that reformats/reorganizes the data for that view.
so, for example, if your @FetchRequest
tracks Entries
, but your view only shows a list of specific data about (a subset of) those entries (using various filter, map, or dictionary methods), then write your List as
List {
ForEach( myFunction(allData) ) { entry in
// ...
}
}
where myFunction
does whatever data transformations are necessary to produce an array or sequence of Identifiable data to drive the list.
hope that helps,
DMG