swiftuserdefaults

How to clear the complete storage in UserDefaults without using removeforObject Method


i want to clear the complete storage in userDefault without using Remove Object method avaliable in userDefaults

this is func i wrote but not sure is this the write way of doing it.

  public func cleanCompleteStorage(){
        let domain = Bundle.module.bundleIdentifier
        UserDefaults.standard.removePersistentDomain(forName: domain)
        UserDefaults.standard.synchronize()
    }

Solution

  • Yes That code certainly removes all the userdefaults in storage. I manually verified by printing all the data before and after that code and it removes it. Personally using same code for my project.