Saving data first time in UserDefaults on macOS creates a plist file at Containers folder path but after deleting and saving different data next time, previuos data(before deleting the app folder) also populates in plist file.
if let test = UserDefaults(suiteName: "my_test_app_userdefaults_suite") { test.setValue("opt_in_1", forKey: "email_1") test.setValue("opt_in_2", forKey: "email_2") test.setValue("opt_in_3", forKey: "email_3") test.synchronize() }
Steps:
- Run the macOS app with above source code, which saves key-value pairs in UserDefaults.
- Checked the UserDefaults plist at path
/Users/rahulmahajan/Library/Containers/com.TestuUserDefaults/Data/Library/Preferences/my_test_app_userdefaults_suite.plist
and all the data is available there, which is good. - Now, deleted the app folder at path
/Users/rahulmahajan/Library/Containers/com.TestuUserDefaults
. - Commented the
opt_in_2
andopt_in_3
statements, ran the app. - Checked the plist at path from Step-2, the lines commented in Step-4 are auto-populated in plist.