My Code below adds another entry to the array if the button jux is pressed. However the new entry is not being saved. The entries that are already their are saved but I can get any new entries to be saved.
VC1
@IBAction func jux(_ sender: Any) {
if let nextvc2 = self.storyboard?.instantiateViewController(withIdentifier: "JUDO") as? judoScores {
nextvc2.loneScore = String(dx)}
}
VC2
import UIKit
class golfCourseScores: UIViewController {
var array = ["horse", "cow", "camel", "sheep", "goat"]
public var loneScore: String?
var myArray = String()
@IBOutlet var numbers: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func jux(_ sender: Any) {
numbers.text = String(describing: array)
array.append(loneScore!)
UserDefaults.standard.set(array, forKey: "numbersWithCreationDates")
UserDefaults.standard.synchronize()
} }
@timswift. Thanks very much for your question. In looking at your code, I am not seeing where you are assigning a value to the String property, “loneScore”. I do see you declaring it, but I don’t see where a value is being assigned to it. However, you do add this value to your array, which you then store in your UserDefaults. I’m guessing the reason why you don’t see anything saved to your array is because the object you’re adding (i.e. loneScore) has no value.
@timswift If it’s being sent from another VC, I still don’t see where the value of loneScore is being updated. Where in the current VC is this value being updated?