defaultIsolation option and Core Data

When creating a new project in Xcode 26, the default for defaultIsolation is MainActor.

Core Data creates classes for each entity using code gen, but now those classes are also internally marked as MainActor, which causes issues when accessing managed object from a background thread like this.

Is there a way to fix this warning or should Xcode actually mark these auto generated classes as nonisolated to make this better? Filed as FB13840800.

nonisolated
struct BackgroundDataHandler {
    @concurrent
    func saveItem() async throws {
        let context = await PersistenceController.shared.container.newBackgroundContext()
                
        try await context.perform {
            let newGame = Item(context: context)
            
            newGame.timestamp = Date.now // Main actor-isolated property 'timestamp' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode
        
            try context.save()
        }
    }
}

Turning code gen off inside the model and creating it manually, with the nonisolated keyword, gets rid of the warning and still works fine. So I guess the auto generated class could adopt this as well?

public import Foundation
public import CoreData

public typealias ItemCoreDataClassSet = NSSet

@objc(Item)
nonisolated
public class Item: NSManagedObject {
    
}

I think what you did - adding nonisolated - is correct. Also needed for SwiftData and at-ModelActor.

defaultIsolation option and Core Data
 
 
Q