I had tested this extensively in the past before starting the project I'm working on. I copied and pasted the code into my new project, so it should work. All I want it to do is reload the tableView every minute, so that the clocks displayed on the tableView reload.
func setMinutesForReload(){
//get calender object
let calender = Calendar.current
//curent date
let now = Date()
//create an array of dates to store minutes
var minutes = [Date]()
//timer array to store timers
var timers = [Timer]()
//set a run loop
for i in 0...23{
for j in 0...59{
minutes.append(calender.date(bySettingHour: i, minute: j, second: 0, of: now)!)
timers.append(Timer(fireAt: minutes[j], interval: 0, target: self, selector: #selector(minutelyReloadTimer), userInfo: nil, repeats: false))
RunLoop.main.add(timers[j], forMode: RunLoop.Mode.common)
}
}
}
@objc func minutelyReloadTimer(){
self.cityTableView.reloadData()
}
Oddly enough, when I run the app and set a breakpoint, I see that it calls minutelyReloadTimer() immediately, 59 times in a row (I counted).
Is this an issue with a recent Xcode/Swift update, or am I missing something that I'm not seeing?