Im trying to set an array of objects to user defaults but is not appending.
declaring the var for the array in my AllFormulas Class:
let defaults = UserDefaults.standard
static var lineOne1 = UserDefaults.standard.array(forKey: "line1") as? [Formulas] ?? []
init() {
//formula names and values
then im starting with an empty array
lineOne1 = []
}
appending to the array in my AddViewController Class :
func lineOneAdd() {
let line1 = lineOne1
lineOne1.append(formulaAppend)
defaults.set(line1, forKey: "line1")
defaults.synchronize()
}
then calling the userDefaults in view did load in MainViewController Class:
line1[indexPath.row] // as my cellForRowAt in tableView
print(line1)
//which prints : []
any idea what im doing wrong? thanks in advance