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?

4

1 回答 1

4

如果您从手机中删除该应用程序,所有UserDefaults将被自动删除。如果你想删除一个特定的,你可以使用UserDefaults.standard.removeObject(forKey: "key"),或者你想删除所有的 UserDefaults,使用这个:UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)。这将清除您的代码设置的所有UserDefaults,让您有一个全新的状态,就像应用程序已被删除并重新安装一样。

于 2017-02-03T12:29:13.593 回答