How to clear locally cached SwiftData database on macOS

I am developing a SwiftData application using CloudKit.

I have been playing with the app for a while and populated the database. Recently I decided to change the type of an attribute. So I reseted the scheme in CloudKit Console to the production one, which actually is empty for now, so I restart from scratch.

Unfortunatly, the locally cached database on my Mac is using the old schema and my app fails loading the ModelContainer because of the type incompatibilities. I would like to delete the locally cached database but I haven't a clue of where it can be. I do not want to go through a migration plan for that.

Does someone know where can I find it ?

Chris tof

Accepted Reply

Found the path with that code :

        let urlApp = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).last
        let url = urlApp!.appendingPathComponent("default.store")
        if FileManager.default.fileExists(atPath: url.path) {
            print("swiftdata db at \(url.absoluteString)")
        }

THen once in that folder I did

rm -rf default*

And the local coach is gone!

Replies

Found the path with that code :

        let urlApp = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).last
        let url = urlApp!.appendingPathComponent("default.store")
        if FileManager.default.fileExists(atPath: url.path) {
            print("swiftdata db at \(url.absoluteString)")
        }

THen once in that folder I did

rm -rf default*

And the local coach is gone!