Xcode 16 MacOS Sequoia SwiftData not saving data after running application

After upgrading to MacOS Sequoia and Xcode 16 my app was behaving oddly. While running the application from Xcode, the app appears to save data, but running the app again from Xcode, the data is not there. If I open the app on the iPhone, run it and create data, the data persists even after I kill the app from the app switcher.

I went many rounds through my code and found nothing that helped. I finally ran the sample app that appears when you begin a new project and that is behaving the same way. There are errors thrown.

error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift"

Answered by DTS Engineer in 809724022

"I stop the app with the stop button in Xcode. I launch the app from Xcode again. The data is gone."

OK, I tried the sample again on my iOS 18 simulator (22A3351) and did see the issue: If I stop running the app immediately after adding a trip, the trip is not persisted.

I believe this is related to the timing of autosave – If I save the context explicitly after adding the trip, as shown below, the issue will go away:

private func addTrip() {
    withAnimation {
        let newTrip = Trip(name: name, destination: destination, startDate: startDate, endDate: endDate)
        modelContext.insert(newTrip)
        do {
            try modelContext.save()
        } catch {
            print("Failed to save model context: \(error)")
        }
    }
}

@cmartinpilot and @purelyapps: Would you mind to double check if you see the same thing on your side?

If that is the case, you can fix the issue by saving the context after making a change. Meanwhile, I’d suggest that you file a feedback report to see if the SwiftData folks would see that a bug – If you do so, please share your report ID here.

Regarding the other error messages:

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

This is a known bug that folks reported months ago, as discussed in the error: the replacement path doesn't exist: post. You can verify if it is still there with the latest iOS 18.1 beta.

"<0x134159cc0> Gesture: System gesture gate timed out. ... -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform ..."

These messages are log noice. You can safely ignore them, as described in On Log Noise.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Same.

error: the replacement path doesn't exist: "/var/folders/2r/9jt0mn9119n3r4tj2qgff5s80000gq/T/swift-generated-sources/@__swiftmacro_18t<Blabla>_.swift"

Same here, has anyone filed a feedback or radar for Apple?

Not yet. I wanted to see if this was a thing first. I’ll do that tomorrow.

I run the SwiftData version of the Adopting SwiftData for a Core Data app sample app on macOS Sequoia 15.0 (24A335) with Xcode 16.0 (16A242d), and it doesn't demonstrate the issue you described. Would you mind to give it a try, and share the exact steps you use, if you do see the issue on your side?

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I have since upgraded to MacOS 15.0.1 & iOS 18.0.1

I did and had the same issue. Here are the steps I took. I downloaded the app. Ran the app in Xcode on my iPhone 13 running iOS 18.0.1. The app runs and immediately errors are thrown in the console. I tapped the plus button and receive this error:

<0x134159cc0> Gesture: System gesture gate timed out.

After I fill out the form, and tap done, this error is thrown:

error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_11SampleTrips12TripListViewV5trips5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_11SampleTrips12TripListViewV5trips5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_11SampleTrips12TripListViewV5trips5QueryfMa.swift"

The trip populates to the list view and all seems fine. I can edit the view by tapping on it. I changed the date and when returning to the list view, it shows the update. I can add trips. I added one more and it populates just fine. At some point I did receive these errors:

CoreSVG has logged an error. Set environment variabe "CORESVG_VERBOSE" to learn more.

-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID. inputModality = Keyboard, inputOperation = <null selector>, customInfoType = UIEmojiSearchOperations

I stop the app with the stop button in Xcode.

I launch the app from Xcode again. The data is gone.

I stop the app with the stop button in Xcode.

I launch the app from Xcode. I add new data and receive the same error about the replacement path doesn't exist...

I stop the app with the stop button in Xcode.

This time when I run the app, the data persists. This represents the first time I have seen data persist.

I have seen the data persist now over multiple starts with Xcode and starting the app on the device. It appears to have corrected itself.

I decided to check the sample app that appears when you select SwiftData as your storage option in a new project. It still behaves the same.

I press the play button in Xcode. The app is loaded onto the phone wirelessly. It runs and I immediately get the replacement path error.

error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift" error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift"

I tap the add button 3 times.

I stop the app from Xcode.

I start the app from Xcode.

The data does not show in the list view.

I repeat this to see if it corrects itself like the other app did, and it continues this behavior over 3 starts.

If I start the app on the phone itself, tap the add button twice, kill the app from the app switcher, then restart the app, the data is shown in the list view.

If I then run the app from Xcode, the data IS shown in the list view.

I delete one item.

Stop the app in Xcode.

Start the app in Xcode.

Both items are there. It did not register the delete from the last app launch.

Experiencing the same issue in my app after upgrading to Xcode 16. When running the app from Xcode the data does not persist.

Launching the app from the device everything seems to work fine, data changes are persisted across launches.

The only log I see when running from Xcode is "CoreSVG has logged an error. Set environment variabe "CORESVG_VERBOSE" to learn more.".

Everything was working fine in Xcode 15.

Accepted Answer

"I stop the app with the stop button in Xcode. I launch the app from Xcode again. The data is gone."

OK, I tried the sample again on my iOS 18 simulator (22A3351) and did see the issue: If I stop running the app immediately after adding a trip, the trip is not persisted.

I believe this is related to the timing of autosave – If I save the context explicitly after adding the trip, as shown below, the issue will go away:

private func addTrip() {
    withAnimation {
        let newTrip = Trip(name: name, destination: destination, startDate: startDate, endDate: endDate)
        modelContext.insert(newTrip)
        do {
            try modelContext.save()
        } catch {
            print("Failed to save model context: \(error)")
        }
    }
}

@cmartinpilot and @purelyapps: Would you mind to double check if you see the same thing on your side?

If that is the case, you can fix the issue by saving the context after making a change. Meanwhile, I’d suggest that you file a feedback report to see if the SwiftData folks would see that a bug – If you do so, please share your report ID here.

Regarding the other error messages:

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

This is a known bug that folks reported months ago, as discussed in the error: the replacement path doesn't exist: post. You can verify if it is still there with the latest iOS 18.1 beta.

"<0x134159cc0> Gesture: System gesture gate timed out. ... -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform ..."

These messages are log noice. You can safely ignore them, as described in On Log Noise.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Xcode 16 MacOS Sequoia SwiftData not saving data after running application
 
 
Q