TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: HowTo remove MacOS App Data when started from Xcode

Forums > macOS


after creating some small IOS apps with SwiftUI and SwiftData, I am now trying to write a small test app for MacOS. I also use SwiftData to keep data persistent. The first version works so far, but now I want to customize my @Model class. I noticed that I don't know a way to completely delete a MacOS app started via XCode. If I stop the app, delete the data from "/Users/ralfb/Library/Developer/Xcode/DerivedData/SyncDataV2... " and then restart it, the items that I added previously and that are stored in SwiftData are still there.

Question: How can I completely delete a MacOS app launched from Xcode, including the SwiftData data, from the system?

I am grateful for any tips :-)

Regards, Ralf


Hey, perhaps this can help. In Systemsettings -> General -> Memory is a group "Developerteam"

Lookm inside this entry to delete Caches, p4erhaps also for the SwiftData

Regards, Marcel


Hey Marcel, Thanks for the hint, but unfortunately this will not delete SwiftData :-/

Regards, Ralf



perhaps some background to my question. I have a SwiftData model and would now like to add another variable. When I start the app afterwards, the app crashes because the SwiftData DB still exists with the old model.

Maybe there is another way to extend the model?

Regards, Ralf



Hi Marcel,

The post describes my problem, but unfortunately the solution was not published. The note with @Relationship is interesting, but unfortunately I don't have the idea of how I would have to implement it.

Anyways, thank you very much for your great support!

Regards, Ralf



I have now tested a bit again, and even though I still haven't found a way to completely delete the app including the SwiftData database, it seems to work now that I can add more properties to the model. I'm not sure why I got an error on the previous attempts, maybe I did something different now. Here are the steps that worked for me:

  1. added new variable in @Model class.
  2. deleted initializer (init)
  3. have the initializer recreated via Xcode (enter init and then XCode will suggest it)
  4. where a new item is added, the new variable is added - Xcode draws attention to the missing arguments during the build

I was then able to build the project and start it without any problems.

Nevertheless, I would be interested in knowing how to delete the SwiftData database, as with IOS.

Greetings, Ralf



After doing some more research and testing, I would like to share my findings here in the hope that it might help some of you.

Here are my findings:

  1. it is possible to programmatically delete the contents of the database:

Then close and restart the app and no more content will be available.

  1. the path to the SwiftData SQLlite database

The following command outputs the path to the Swift DB:

let theURL = NSPersistentContainer.defaultDirectoryURL()
print("**** URL: \(theURL) ****")

What I have not yet understood is that if I initialise SwiftData as described by Apple and start my app, add items, then the above-mentioned path is still without content. Nevertheless, the app works without any problems and the data is persistent.

However, it is possible to define the path to the database in the code when initialising the ModelContainer.

var sharedModelContainer: ModelContainer = {
        let schema = Schema([

        let baseURL = NSPersistentContainer.defaultDirectoryURL()
        let storeURL = baseURL.appendingPathComponent("ralfb-SyncDataV2.sqlite")

        let modelConfiguration = ModelConfiguration(schema: schema, url:  storeURL)
        do {
            return try ModelContainer(for: schema, configurations: [modelConfiguration])
        } catch {
            fatalError("Could not create ModelContainer: \(error)")

The path is defined via baseURL and storeURL, and when I then start the app I find the following files under the path (baseURL):


If I delete this data and the DerivedData, then all app data, including the persistent data, is deleted.

Regards, Ralf


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.