I have an app that have a struct (lets call it Notes). I also have an array of Notes. I stored this array in UserDefaults using codable and decode and encode. Retrieve Code:
if let data = UserDefaults.standard.value(forKey:"NotesArray") as? Data {
let decodedSports = try? PropertyListDecoder().decode([Notes].self, from: data)
NotesArray = decodedSports ?? []
}
and the set code:
UserDefaults.standard.set(try? PropertyListEncoder().encode(NotesArray), forKey:"NotesArray")
My app is already up and running. Now let us say I have 'createdDate' and 'modifiedDate' variables in this struct. And now after a while I want to add a new variable called 'editable'.
How can I do that without losing the existing data in the array? I have searched a lot and couldn't find any method to solve this issue.