Asperi is right that this is an simply an opinion, and up to you.
Here are some things I've noticed about persistance in macOS.
UserDefaults
(which @AppStorage
uses under the hood) allows you to store simple types, and Data (which could theoretically represent any type).
UserDefaults
are automatically written to a property list residing under:
~/Library/Preferences/<yourbundleid>.plist
If your app is sandboxed it'll be under:
~/Library/Containers/<Your Container>/Library/Preferences/<yourbundleid>.plist
If you are using a custom method of saving your config/preferences, most developers store such data inside:
~/Library/Application Support/Your App/
I would encourage you to not store your config inside their home directory, unless for some particular reason you absolutely need it there. It can make your app harder to uninstall, and it clutters their home folder!
UserDefaults vs Custom Config?
Once again, just my opinion, but here is the rule I generally follow:
Which is easier?
I usually find myself using UserDefaults for in-context preferences, like the typical "don't bother me about this again" checkbox on a dialog.
I also use it often for remembering state (which becomes really awesome with @AppStorage
). As a side note, UserDefaults
automatically reads and writes the preferences to disk which in turn means less code.
I do find myself occasionally using custom configs when the preferences are managed outside of the view/vc code, or when my config structure is rather complex. If I'm going to have to go through the work of deserializing/reserializing structs
to Data
for storage in UserDefaults, I might as well store them and manage them myself.
Size concerns
I've always heard that it's "bad" to store large amounts of preferences inside UserDefaults. While UserDefaults is certainly capable of storing the 4KB you mentioned in your question, there are some situations where you'll want to use alternatives. I found the following SO thread rather enlightening on this subject.