How to delete an encoded property list stored in a file path. I have stored user information as an encoded property list in a file path.
let loggedDetailsFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(SessionKeys.loggedDetails)
func saveLoggedDetails(data: LoginModel) {
do{
let data = try encoder.encode(data)
try data.write(to: loggedDetailsFilePath!)
}catch{
print("error encoding the item \(error)")
}
}
LoginModel is my Codable model
When the user is logging out from the app the property list need to be cleared or deleted
I hope this will work for you to store data in UserDefaults
Above extension is for store & fetch Codable model to UserDefaults
Here is function to store any Codable Model :-
as per above function you can easily remove data from UserDefaults