Creating a non-repeating timer is simple with the following code:
Non-repeating timer in Swift
//Non-repeating Timer in Swift
let timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.printMessage), userInfo: nil, repeats: false)
- timerInterval denotes the number of seconds between the firings of timer.
- target denotes the object to which send a message specified by selector.
- selector denotes the message to sent to the target after the timer gets fired.
- UserInfo can be used to send additional information about timer event in a dictionary format.
- repeats denotes whether a timer is repeating or non-repeating. If it is set to true, the timer reschedules itself after getting fired automatically until it is manually invalidated and if it is set to false, the timer fires once and gets invalidated automatically.