Where can I get a list of all UserDefaults keys?

Anyone know where I can get a list of all the UserDefaults keys? I can't find it in documentation.

Answered by QuinceyMorris in 269684022

Well, yes, you are mistaken that this key (if it existed) would be in user defaults (aka "preferences").


User defaults are values used to configure individual apps, and each app has its own set of user defaults. It is possible to put user defaults in other "domains", which allows them to be shared across apps and devices to some degree, but this limited and not intended to control system-wide values such as standard font sizes.


Instead, such "system settings" are exposed to your app as various properties in various frameworks. For example, the AppKit framework has NSFont.systemFontSize to return the standard system font size.


Note that in iOS, the Settings app is "merely" an aggregation of various system settings stored in various ways (not necessarily using the UserDefaults mechanism), packaged with a UI for the benefit of users. 3rd party apps can expose their own settings via the Settings app, or they can provide their own UI.


Note also that an app may well store more information in UserDefaults than is ever exposed directly to users as settings. For example, an app that displays a long table view might save the scroll position in UserDefaults so that it can be restored the next time the app runs, but the user would never see a setting that shows or sets the information.


Finally, there is no single default or preference or setting for "font size". When a user chooses to make fonts larger globally (via the Settings app), the app is expected to use various APIs to request the recommended font size for a given scenario (body, heading, label, etc). The actual size it's instructed to use will be the product of some calculation involving settings and device characteristics, and likely isn't stored anywhere.


So, as ddunham said, there is no list of UserDefaults keys, since they are basically different in every app (except when agreed upon for some sharing scenario), and there is no centralized list of settings, and they are not in general stored under known keys.

All values:


print(UserDefaults.standard.dictionaryRepresentation().values)


All keys:


print(UserDefaults.standard.dictionaryRepresentation().keys)


All keys and values:


print(UserDefaults.standard.dictionaryRepresentation())

That helps, but that list doesn't seem complete. Where do I get a list of the keys that hasn't been saved or registered in UserDefaults?

You don't mean these, do you?


See Also

Related to this is "UserDefaults.standard". If I have read docs correctly, there are some keys here that control your app's default values for features that the system provides to your app. I've seen mention of a few keys that can be set here. E.g. "NSDisabledCharacterPaletteMenuItem" true is supposed to hide the "Emojis & Symbols" menu item. But I haven't seen any list of all the ones that the system understands.

Where can I get a list of all UserDefaults keys?
 
 
Q