I followed this tutorial, Save custom objects into NSUserDefaults to figure out how to save data with classes. My problem is that I need to update this data without overriding the old data. I am currently trying
let data = [ToDo(name: cardTitle.text!, length: 7, startDate: Date(), itemArray: subarray)]
let newData = decodedData.append(data)
let encodedData: Data = NSKeyedArchiver.archivedData(withRootObject: newData)
defaults.set(encodedData, forKey: "data")
defaults.synchronize()
but this returns an error because trying to append data
to decodeData
returns ()
and I have no idea how to fix it. The only thing that works is
let data = [decodeData[0], ToDo(name: cardTitle.text!, length: 7, startDate: Date(), itemArray: subarray)]
but this won't work because I need to use more than just the data at index 0.
Has anyone run into this before? Any thoughts?