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've submitted feedback FB14898357 on this.

I ran Into these. deleted the simulator default.store files deleted the derived data for the app deleted all the cached simulators stuff in derived data. quit and restart Xcode launch app on the simulator and recreated the store. All gone for now.Obviously I used a big hammer but it worked.

This worked for me:

Open simulator On the Menu on top:

Device -> Erase All Content And Settings... Device -> Restart

Quit Simulator Quit Xcode

I'm getting a similar error but because I am using HomeKit, I've never run the app in the simulator.

I've deleted the app off my device and cleared derived data but still get the error.

It delays loading certain parts of my SwiftData model, which breaks the app when it thinks that is complete.

I amend my comment: my model is present and working UNTIL these errors pop up, then the data disappears

I have the same error and In my app I think it only occurs if I use a list on an empty array in SwiftData.

I have tried to display the list of items in different views and it always lists the file where I am attempting to loop through the data

Im using the Xcode 16 RC

I've updated my feedback to say that the problem exists when using Xcode 16 RC.

Upgrading Xcode from 15 to Version 16.0 (16A242d) caused the errors to appear. No issues before the upgrade.

Getting them on basic @Query var items: [Item] on views.

"error: the replacement path doesn't exist:"

Deleting the app on real devices did not help.

Upgrading from Xcode 15 to 16.0 (16A242d) IOS 18. Now I get error: the replacement path doesn't exist: "/variable/folders/....swift" <- this error is green.

Then: Publishing changes from background threads is not allowed; <- this error is red.

The app worked fine in IOS 17.7 and Xcode 15

I have some information that may be helpful to others, and to those addressing the Feedback created.

I have the same issue in a brand new app, created yesterday with Xcode 16 (16A242d). Deleting Derived Data and Erasing my simulator did not help.

The issue started when I added a new relationship to one of my Model classes - I've been able to 'fix' the crash (not entirely proven yet, but the initial crash is no longer happening) by moving the initialization of the relationship from the field definition to the constructor. In other words, this code crashes on launch:

    @Relationship(deleteRule: .cascade)
    var selections = Selection()

While this code does not:

    @Relationship(deleteRule: .cascade)
    var selections: Selection

    init() {
        selections = Selection()
    }

I have filed a feedback for this issue as well, and referenced this thread: FB15250668

I'm seeing this error and I'm not even using SwiftData in this app. It's occurring when I update an array property on an Observed model class.

Like other comments, this only started with Xcode 16.

I have a SwiftData document-based app with iCloud documents enabled, and lots of one-to-many @model relationships.

I have the same issue as reported, and I am getting the error:

Publishing changes from background threads is not allowed; make sure to publish values from the main thread

I also get a crash shortly after with the breakpoint message:

SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData.

I wonder if the two errors are related.

I have not tested on the simulator, but have tested on iPad Pro M1 and iPhone 12

Both errors have only appeared in ios18, and the app has been running great for many months in ios17 with no crashes. Suddenly ios18 is released and the entire app is broken. Grrrrr.

I think I have made some progress with this by introducing manual saves when working on the model, so for example, instead of:

 selectedItem = item

I have replaced with:

 do {
    try modelContext.transaction {
        selectedItem = item
  } catch {
        print("unable to save change due to error \(error)")
 }

Items are now successfully persisting, and the error:

SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData.

Seems to have gone away.

It seems like the error was something to do with the way that changes are stashed and saved in the background by SwiftData, I am not an expert but my best guess is that it is related to the recent changes in concurrency architecture.

I have also found SwiftData to be much more reliable if you work directly on elements derived from @Query in the view, rather than trying to save on @Bindable from a parent. I pass the UUID around the views and then filter the arrray from @Query for the id.

I don't know if this will help or not but: Running the app on the Simulator pops up an message:

error: the replacement path doesn't exist:
 
 
Q