I've been working on a side project in swift that is basically a word of the day app. I've stored 30 words and content into an array and have been trying to update the word each day. I've tried a few fixes but to no avail. I can only ever get the first array to show even if I change the date on my phone.
Are the wordNumber and wordOfDay in conflict? How can I adapt this so a new word pops up each day?
let wordList =
[
Words(word: "aaa", pronounciation: "bbbb", type: "noun", definition:"blah"),
Words(word: "bbb", pronounciation: "cccc", type: "adjective", definition:"blah")
]
var wordNumber = 0;
class ViewController: UIViewController {
@IBOutlet weak var wordLabel: UILabel!
@IBOutlet weak var pronounciationLabel: UILabel!
@IBOutlet weak var wordTypeLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
updateWord()
}
@IBAction func prepareForUnwind (segue: UIStoryboardSegue){}
func updateWord()
{
let date = Date()
let dateIndex = Int(date.timeIntervalSince1970) / (60*60*24)
let wordOfDay = wordList[dateIndex % wordList.count]
wordLabel.text = wordList[wordNumber].word
pronounciationLabel.text = wordList[wordNumber].pronounciation
}
}