本文介绍了如何在Swift中从UserDefaults中按套件名称删除所有数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用以下名称创建了用户默认值,
I have created user defaults with names below,
let prefs1 = UserDefaults.init(suiteName: "UserAccount")
let prefs2 = UserDefaults.init(suiteName: "UserInfo")
然后,我在这些套件中添加了一些值.即
Then I have added some values to those suites. i.e.
prefs1.set(true, forKey: "Key1")
prefs1.set(true, forKey: "Key2")
prefs2.set(false, forKey: "Key1")
prefs2.set(false, forKey: "Key2")
现在,我要删除prefs1
(即名称"UserAccount"),而不要删除prefs2
.我尝试过,
Now, I want to remove the prefs1
(i.e. name "UserAccount"), but not prefs2
. I tried,
UserDefaults.standard.removePersistentDomain(forName: "UserAccount")
但是它没有移除.我对forName
和suiteName
But it did not remove. I am getting confused with, forName
and suiteName
如何从UserDefaults
中删除套件,使其他套件在Swift中保持完整?
How to remove a suite from UserDefaults
keeping other suites intact in Swift?
推荐答案
func removePersistentDomain(forName domainName: String)
https://developer.apple.com/documentation/foundation/userdefaults /1417339-removepersistentdomain
这篇关于如何在Swift中从UserDefaults中按套件名称删除所有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!