问题
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