Search code examples
iosiphoneuserdefaults

Easy way to remove UserDefaults (without coding)


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?


Solution

  • 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.