How to call function on time? Also How to Call only once time in swift 3?
i need to call one function one time only, so how can possible to call function only one time like after 3 seconds?
How to call function on time? Also How to Call only once time in swift 3?
i need to call one function one time only, so how can possible to call function only one time like after 3 seconds?
 
    
    You can do something like,
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
   yourFunction() // call your functin here
}
You can also use DispatchQueue.global().asyncAfter if you don't want to perform your task on main thread!
And refer this post to manage it one time only!
 
    
    private let _onceToken = NSUUID().uuidString
DispatchQueue.once(token: _onceToken) {
     print( "Do This Once!" )
     DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
         yourFunction() // call your functin here
     }
}
It will execute your method only once and delay your method for 3 seconds.
 
    
    For start timer:
  var timerUpdateArray:Timer!
  func callTimer(){
        self.timerUpdateArray = Timer.scheduledTimer(timeInterval: 1, 
        target: self, selector: #selector(yourFunc), 
        userInfo: nil, repeats: true)
   }
For stop timer:
 self.timerUpdateArray.invalidate()
