I'm sharing a Core Data store with my action extension, which adds data to it. My app has a SwiftUI view that presents this data, fetched with a FetchRequest
:
private struct VideosScrollView: View {
@Environment(\.managedObjectContext) private var viewContext
private var fetchRequest: FetchRequest<Video>
init(sortOrder: String, tagIds: String, showWatched: Bool) {
fetchRequest = Video.getFetchRequest(sortingBy: "addDate",
with: sortOrder,
showWatched: showWatched,
tagIds: tagIds)
}
var body: some View {
ScrollView {
if fetchRequest.wrappedValue.isEmpty {
ContentEmptyView()
} else {
ForEach(fetchRequest.wrappedValue) { item in
VideoCellView(video: item)
}
}
}
}
}
After adding data from the action extension and going back to the app, the view is not updated. Only after CloudKit finished a sync is that the view notices something changed and updates itself.
How can I force my SwiftUI view to update when data changes in the action extension?