If I query an entity with a relationship to another entity, and then I update that related entity, the view does not refresh automatically. I'm 'forcing' it now, but that doesn't seem right. What's the right way?
See code sample:
See code sample:
Code Block swift struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [], animation: .none) private var categories: FetchedResults<Category> private func forceRefresh() { viewContext.refresh(categories[0], mergeChanges: true) } var body: some View { VStack { List { ForEach(categories) { category in Section { Text("\(category.name!)").font(.title) } ForEach(category.items?.allObjects as! [Item]) { item in Button { item.name = "\(UUID())" } label: { Text("\(item.name!)").font(.caption) } } } } Divider() Button { forceRefresh() } label: { Text("Force Refresh").foregroundColor(.blue) } } } }