background info: this application scans a color, then, if the user would like to, saves the color to a UITableView using UserDefaults. The variables in here are byproducts of the algorithm used earlier in the program.
When I look at the Table, instead of their being new elements, the one I saved is replaced.
Here is the code, I am trying to save this to userdefaults, but I don't think userdefaults is the problem.
these are the pre-defined arrays. they are not part of the class.
var NameList = [String]()
var HexCodeList = [String]()
var RedList = [CGFloat]()
var BlueList = [CGFloat]()
var GreenList = [CGFloat]()
this is the function that is adding the variables to their corresponding arrays and saving them to user defaults. this is part of a viewcontroller class
@IBAction func SaveColor(_ sender: Any) {
let alertController = UIAlertController(title: "Save Color", message: "Please name the color you would like to save:", preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "Confirm", style: .default) { (_) in
if let field = alertController.textFields?[0] {
// store your data
//ColorList.append(Color(name: field.text!, hexCode: self.hexCode, Red: self.Red, Green: self.Green, Blue: self.Blue))
//UserDefaults.standard.set(ColorList, forKey: "ColorList")
NameList.append(field.text!)
UserDefaults.standard.set(NameList, forKey: "NameList")
HexCodeList.append(self.hexCode)
UserDefaults.standard.set(HexCodeList, forKey: "HexCodeList")
RedList.append(self.Red)
UserDefaults.standard.set(RedList, forKey: "RedList")
GreenList.append(self.Green)
UserDefaults.standard.set(GreenList, forKey: "GreenList")
BlueList.append(self.Blue)
UserDefaults.standard.set(BlueList, forKey: "BlueList")
UserDefaults.standard.synchronize()
print("NameList - 2nd", NameList)
} else {
// user did not fill field
}
}
I'm pretty sure this is all the code that matters, but if you need more to help me out I will gladly post it all
thanks much