I have a variable named currentYear that is set to 2000 for default purposes. currentYear is a variable in my array of strings so the string knows which year it is. This is in a file which has no class. These values are globally accessible.
import UIKit
var currentYear = 2000
var array = [
"The year you pressed is \(currentYear)",
]
In the ViewController I have buttons with tags that are equal to the year it contains: 2013, 2014, 2015 and 2016. When the button is pressed, it goes to another ViewController.
import UIKit
class ViewController: UIViewController {
@IBAction chooseYearBtnPressed(sender: AnyObject) {
currentYear = sender.tag
print(array)
performSegueWithIdentifier("CustomSegue", sender: nil)
}
}
Before the recent xcode update, this worked just fine. Whenever the button was pressed, the array that is loaded has the same currentYear as whatever was the new value. Now it doesn't. After assigning currentYear a new value, the currentYear in the array remains 2000.
How can I fix this, so currentYear would still change based on whatever I pass as a new value?
Solution:
var array: [String] {
return ["The Year you pressed is \(currentYear)"]
}