2

I've seen that there are several ways to remove the UserDefaults via code.

I've deleted a testing app from my phone but the UserDefault values are still there.

Is there an simple way of removing the UserDefaults instead of implementing a function to delete them?

andih
  • 5,570
  • 3
  • 26
  • 36
  • 5
    If you are deleting the whole app from the phone and reinstall it, userdefault shouldn't contains data, you might want to check how data has been filled – Ahmad F Feb 03 '17 at 12:12

1 Answers1

4

If you remove the app from your phone all the UserDefaults will be removed automatically. If you want to remove a particular one, you can use UserDefaults.standard.removeObject(forKey: "key"), or you want to delete all UserDefaults, use this: UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!). This will clear all of the UserDefaults that have been set by your code leaving you with a fresh slate just as if the app had been deleted and reinstalled.

anas.p
  • 2,246
  • 19
  • 26