I'm working on a new version of my macOS app which stores a version
property in the UserDefaults.standard
. Now I would like to test the update process from version 1 to version 2. Only version 2 writes the version
property. So version 1 should not have it.
UserDefaults: App Version 1
UserDefaults: App Version 2
It's a sandboxed app, so I go to here and delete whole container.
~/Library/Containers/com.example.myapp/
I switch to Xcode, checkout version 1 in my git history, and run the app.
When running version 1 of the app, it writes the settings
property. But at the same time it also writes the version
property, which version 1 doesn't even have implemented. So, I assume there's some weird caching issue happening.
Is there something else I have to do in order to run the app "from scratch"?
I've talked to an Apple engineer and it turns out, that there is a deamon in the background used for accessing the user defaults.
Only the deamon is supposed to have access the user defaults in the shared app group. Your apps that are using the user defaults only talk to the deamon, too.
The deamon also has a cache and will return it, because it does not know about your manual changes and thinks the file was not changed.
Kill the deamon
The Apple engineer also said you could technically kill the deamon everytime but that's not the recommended way. They also didn't tell me the name of the deamon.
Use defaults command line tool
The recommended way seems to be to use the defaults
command line tool. This tool basically does the same as your apps. It talks to the deamon and the deamon will update the actual file. Note that for user defaults in shared app groups you need to specify the whole path to the file. Using the bundle identifier is not enough.
Here's a reference for defaults
: https://ss64.com/osx/defaults.html