I am creating a small application that displays the bus timetables of my city. I use a UICollectionView to display all the timetables:
From 06:00 in the morning to 00:30 in the evening. Buses pass every 30 min.
I would like my cells to scroll automatically according to the time of the day, even if the application is closed. I would like my the cells that display the next bus (e.g. 2:30 pm) display the one at 2:00 pm and automatically scroll after 2:30 pm to display the next bus that comes at 3:00 pm etc... until 00:30 am. And after 00:30, I would like to display the cell that shows 06:00. And the process continues ad infinitum.
extension HomeViewController : UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return busHoursList.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let busCell = collectionView.dequeueReusableCell(withReuseIdentifier: "busCellID", for: indexPath) as! BusCollectionViewCell
busCell.layer.borderWidth = 0.6
busCell.layer.cornerRadius = 15
busCell.layer.borderColor = CGColor.init(red: 170/250, green: 170/250, blue: 170/250, alpha: 1)
busCell.setupDepartureHours(withText: busDepartureHoursList[indexPath.row])
}
}