'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 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hashim Khan