To clear all UserDefault
s from an app, maybe try this:
if let appDomain = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: appDomain)
}
Thanks to Sourabh Sharma for this idea.
Or maybe just:
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
… from netshark1000.
… except apparently removePersistentDomain
doesn’t work when running tests. So maybe try this instead:
for key in Array(UserDefaults.standard.dictionaryRepresentation().keys) {
UserDefaults.standard.removeObject(forKey: key)
}
… from bogen.
… or even just UserDefaults.standard.dictionaryRepresentation().keys.forEach(defaults.removeObject(forKey:))
from Naresh.