Clearing a subset of UserDefaults in Swift [closed]

喜你入骨 提交于 2020-01-07 09:47:34

问题


The use case is that I want to separate my UserDefaults (different business logic may require Userdefaults to be grouped separately) by an identifier just like Android's SharedPreferences. For example, when a user in my app clicks on logout button, I would want to clear his account related defaults but not location of the the device saved in UserDefaults.


回答1:


You can use a Suite name

let user = UserDefaults(suiteName:"User")

let location = UserDefaults(suiteName:"Location")



来源:https://stackoverflow.com/questions/50712737/clearing-a-subset-of-userdefaults-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!