Hey there! I've been tracking a really weird behavior with a List backed by @FetchRequest from CoreData.
When I toggle a bool on the CoreData model, the first time it updates correctly, but if I do it a second time, the UI doesn't re-render as expected. This does not happen if I compile the app using Xcode 16 (targeting both iOS 18 and iOS 26), nor it happens when using Xcode 26 and targeting iOS 18. It only happens when building the app using Xcode 26 and running it on iOS 26.
Here are two demos: the first one works as expected, when I toggle the state twice, both times updates. The second one, only on iOS 26, the second toggle fails to re-render.
Demo (running from Xcode 16):
Demo (running from Xcode 26):
The code:
import SwiftUI
import CoreData
@main
struct CoreDataTestApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
}
}
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)])
private var items: FetchedResults<Item>
var body: some View {
NavigationView {
List {
ForEach(items) { item in
HStack {
Text(item.timestamp!.formatted())
Image(systemName: item.isFavorite ? "heart.fill" : "heart").foregroundStyle(.red)
}.swipeActions(edge: .leading, allowsFullSwipe: true) {
Button(item.isFavorite ? "Unfavorite" : "Favorite", systemImage: item.isFavorite ? "heart" : "heart.fill") {
toggleFavoriteStatus(item: item)
}
}
}
}
.toolbar {
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
}
private func addItem() {
withAnimation {
let newItem = Item(context: viewContext)
newItem.timestamp = Date()
newItem.isFavorite = Bool.random()
try! viewContext.save()
}
}
private func toggleFavoriteStatus(item: Item) {
withAnimation {
item.isFavorite.toggle()
try! viewContext.save()
}
}
}
struct PersistenceController {
static let shared = PersistenceController()
let container: NSPersistentContainer
init() {
container = NSPersistentContainer(name: "CoreDataTest")
container.loadPersistentStores(completionHandler: { _, _ in })
container.viewContext.automaticallyMergesChangesFromParent = true
}
}