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:

I received the following message from Apple Feedback Assistant.

Thank you for filing the feedback report. We have deployed the fix. Please verify this issue with iOS 18.1 Beta 6 and update your bug report with your results by logging into https://feedbackassistant.apple.com/ or by using the Feedback Assistant app.

iOS 18.1 Beta 6 (Build: 22B5069a) https://developer.apple.com/download/ Posted Date: October 7, 2024

I don't have iOS 18.1 Beta 6 on any of my devices. Is there anyone who does and can confirm the fix?

I do not have 18.1 Beta 6.

I started seeing the same issue after restructuring / refactoring some of my Swift projects - all of them relying on newly introduced @Macro syntax elements.

Good news: the error is unrelated to SwiftData and the crashes described further down in this thread are also unrelated to it (neither of my projects uses SwiftData so QED). I believe people are just seeing it more frequent on Xcode 16 + SwiftData because of the heavy use of Macros it introduced.

Using "Product" > "Clean Build Folder.." didn't solve the issue, however what did was the following:

  • "Product" > "Show Build Folder in Finder"
  • navigate up until you're in XCode's "DerivedData" folder
  • find and delete all folders starting with your Projects Name + some random identifier
  • restart Xcode
  • rebuild

So for example my project was called "GPS.io" and the folder was named something like "GPS.io-gsytifiksezewoesjjyadyzossvf" located in "/Users/USERNAME/Library/Developer/Xcode/DerivedData"

[EDIT] I'm on XCode 16.0 (16A242d) and testing against iOS 18.0

Fixed by cleaning XCode's "DerivedData" folder. from the terminal just run this command

rm -rf ~/Library/Developer/Xcode/DerivedData

I'm still seeing the issue on Xcode 16.1 and iOS 18.1.

i have same problem when i get more than one instance of @ModelActor , if i generate single instance and share between tasks, problem solved. Bu this method not best practice!

Someone know solution ?

I have also hit this issue (and continue to do so despite trying all the suggestions made so far). I have clicked on the feedback link, but then just get a feedback not found screen. Has the link changed. Please can you advise?

When you have this error in the logs, try the following:

  1. Get the derived data folder handy.
  2. Clean and Close Xcode.
  3. Find the following folder:

/var/folders/1q/6jw9d6mn0gx1znh1n19z2v9r0000gp/T/swift-generated-sources

  • The random string could be different for you.

  • Delete the contents of the derived data folder.

  • Delete the contents of the swift-generated-sources.

  • In the var/folder..../T folder, scroll to the tip and also delete any dev related files starting with an _.

Now:

  1. Launch Xcode with your project.
  2. Resolve packages if you have any.
  3. Build and run.

Still having this issue. Have tried the recommended. The main issue that I think this causes is that it does not save SwiftData when the simulator is closed. The data is only saved if you wait a while after making the change or specifically save the context after every right, or close the app in the simulator. But not if I just rebuild or stop the simulator.

I'm having the same issue here. Followed the suggestions here and no luck. Haven't tried the beta update but sounds like its still there. Is this an actual error since it's colored green on the console?

Also getting the same logs in Xcode:

error: the replacement path doesn't exist:

I'm not sure if this is debug log noise or something that needs to be fixed.

error: the replacement path doesn't exist:
 
 
Q