|
Hello, 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 Marcel, Thanks for the hint, but unfortunately this will not delete SwiftData :-/ Regards, Ralf |
|
Hello, 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 |
|
Perhaps this can give you he Hint https://stackoverflow.com/questions/77463949/modify-exsiting-data-model-in-swiftdata Regards, Marcel |
|
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 |
|
Hello, 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:
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 |
|
Hello, 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:
Then close and restart the app and no more content will be available.
The following command outputs the path to the Swift DB:
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.
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 |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.