Reputation: 41
When I do defaults read
at the command line, I get over 6000 lines of keys. When I enumerate UserDefaults.standard.dictionaryRepresentation()
in a program (non-sandboxed), I get only about 50 lines of values.
What's the Foundation version of defaults read
? How do I get all the NSUserDefaults keys in a program?
Upvotes: 4
Views: 797
Reputation: 90641
defaults read
without any domain argument reads all domains for the current user. UserDefaults.standard.dictionaryRepresentation()
reads just the current application's domain.
I have no idea why you'd want to read all domains, but you can do it using the CFPreferences API. You start by calling CFPreferencesCopyApplicationList(kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
to get all of the application domains (including the global domain, kCFPreferencesAnyApplication
). Note that this is deprecated without any replacement that I'm aware of. Then, you iterate through those and call CFPreferencesCopyMultiple(nil, eachAppIDInTurn, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)
.
Upvotes: 1