I can not think of how best to implement a repetition of the workout timer cycle. The default cycle is one. exercise list

let exersiseName = ["БЕГ", "ПРЫЖКИ", "ПРИСЕДАНИЯ"] @IBOutlet var nameExersiseLabel = UILabel()//лэйбл с названием упражнения @IBOutlet var timerLabel = UILabel()//лэйбл секундомера var timer = NSTimer() var exersiseTime = 30 var timerRunning = false var i = 0 var sets = 2 //вводим переменную количества циклов которая будет меняться // КАК ЕЕ ПРИМЕНИТЬ ДЛЯ ПОВТОРЕНИЯ ПОКАЗА НАЗВАНИЙ УПРАЖНЕНИЙ И ПРОДОЛЖЕНИЯ РАБОТЫ ТАЙМЕРА ДО ОКОНЧАНИЯ ВТОРОГО ЦИКЛА func Counting(){ exersiseTime -= 1 timerLabel.text = "\(Int(exersiseTime))" if exersiseTime == -1 { i += 1 exersiseTime = 30 timerLabel.text = "\(Int(exersiseTime))" } if i + 1 < exersiseName.count { //Ход тренировки nameExersiseLabel.text = exersiseName[i] as? String } else if i + 1 == exersiseName.count { //Последнее упражнение в тренировке nameExersiseLabel.text = exersiseName[i] as? String } else if i + 1 > exersiseName.count { //Конец тренировки timerLabel.text = "0" timer.invalidate() timerRunning = false } } 

I do not write the timer start button, if someone needs it, I will add

  • not a very clear question - as the first timer did, just do the repetition. - Max Mikheyenko 2:19 pm

1 answer 1

There is a solution!

We declare another variable var count = 0 , set the condition if i + 1 > exersiseName.count first and modify it as follows:

 if i + 1 > exersiseName.count { //Конец цикла count+=1 if (count >= sets) { timerLabel.text = "0" timer.invalidate() timerRunning = false }else{ i = 0 } } //важно: не надо ставить здесь else if .... 
  • You would at least format the code - Max Mikheyenko