SoFunction
Updated on 2025-04-09

Swift 3.0 implements the countdown function of SMS verification code

The following code is shared with you the countdown function of Swift 3.0 to implement the SMS verification code. The specific example code is as follows:

class TCCountDown {
private var countdownTimer: Timer?
var codeBtn = UIButton()
private var remainingSeconds: Int = 0 {
  willSet {
    ("Re-acquire\(newValue)Second", for: .normal)
    if newValue <= 0 {
      ("Get verification code", for: .normal)
      isCounting = false
    }
  }
}
var isCounting = false {
  willSet {
    if newValue {
      countdownTimer = (timeInterval: 1, target: self, selector: #selector(), userInfo: nil, repeats: true)
      remainingSeconds = 60
      (BtnCodeColor, for: .normal)
    } else {
      countdownTimer?.invalidate()
      countdownTimer = nil
      (MainColor, for: .normal)
    }
     = !newValue
  }
}
@objc private func updateTime() {
  remainingSeconds -= 1
}
 }
 //Calling method var countDown = TCCountDown()//Instantiation  = true//Turn on the countdown

The above is the Swift 3.0 implementation of SMS verification code countdown function introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!