ios - 无法删除 NSUserDefaults (iOS) 中的键对象
问题描述
由于某些奇怪的原因,我无法删除 NSUserDefaults 中的某些键。我在做:
UserDefaults.standard.removeObject(forKey: "currentSelectedCategoryID")
print(UserDefaults.standard.string(forKey: "currentSelectedCategoryID"))
"58707"
当我打印该值时,它显示的值与删除对象之前完全相同。我什至尝试过UserDefaults.standard.set(nil, forKey: "currentSelectedCategoryID")
,它正在做同样的事情。
为什么我不能删除我的密钥?
解决方案
我想到了。我正在与我的共享扩展共享我的用户默认值,并且我没有删除该用户默认对象的密钥。
UserDefaults.standard.removeObject(forKey: "currentSelectedCategoryID")
if let shared = UserDefaults(suiteName: {YOUR SUITE NAME}) {
shared.removeObject(forKey: currentSelectedCategoryID)
}
推荐阅读
- python - lambda if 与 python 中的数字列表
- sql - SQL Case 总是使用第一个 Case?
- python - PicklingError:无法腌制任务以将其发送给工作人员
- rust - 如何在 actix 处理程序中设置查询参数的默认选项?
- java - 连接到 mySQL、JPA、Java EE 和 JBoss
- python-3.x - 在 Python3.x 中绘制列表字典(主题词嵌入)
- azure-devops - 在 Terraform 中计算用户的输入?
- oauth-2.0 - Keyclock 与客户端 ID 共享相同的会话
- javascript - React 使用钩子过滤多个 JSON 请求
- c# - 注册表模式和 .net core DI