error: the replacement path doesn't exist:

I'm using SwiftData with an @Model and am also using an @ModelActor. I've fixed all concurrency issues and have migrated to Swift 6. I am getting a console error that I do not understand how to clear. I get this error in Swift 6 and Swift 5. I do not experience any issue with the app. It seems to be working well. But I want to try to get all issues taken care of. I am using the latest Xcode beta.

error: the replacement path doesn't exist: "/var/folders/1q/6jw9d6mn0gx1znh1n19z2v9r0000gp/T/swift-generated-sources/@_swiftmacro_17MyAppName14MyModelC4type18_PersistedPr> opertyfMa.swift"

I also had this issue when refactoring code to use SwiftData. I had marked several properties with the attribute Transient that I did not want to store. When I realized that Views no longer detected changes to these Transient properties, I converted some of these properties from Transient to the Attribute ephemeral. This solved my View update problem. The App worked fine on first launch and pre-populated the data store with default values and allowed me to update and save data. But I would get the error on subsequent launches and the App would crash when fetching the data from the Model that had a mix of Transient and ephemeral. Other Models that had only Transient macro marked properties were fine. Removing the ephemeral attribute and keeping only the Transient macro in my Model eliminated this problem for me.

in my case, I found the cause is the use of ModelContext's batched fetch method: func fetch<T>( _ descriptor: FetchDescriptor<T>, batchSize: Int ) throws -> FetchResultsCollection<T> where T : PersistentModel

The cure for my code is replacing this problematic fetch with the plain fetch method: func fetch<T>(_ descriptor: FetchDescriptor<T>) throws -> [T] where T : PersistentModel

I am not sure this cure is effective in other cases but I feel the current maturity of the batched fetch is very low and very unstable.

error: the replacement path doesn't exist:
 
 
Q