Timers are for when you want to do something once in the future - tickers are for when you want to do something repeatedly at regular intervals. Here’s an example of a ticker that ticks periodically until we stop it.
When we run this program the ticker should tick 3 times before we stop it.
In this Objective-C version, we use Grand Central Dispatch (GCD) to create a timer that fires every 500 milliseconds. The dispatch_source_t is similar to a ticker in that it repeatedly performs an action at regular intervals. We use a block to handle each tick event, printing the current time.
Instead of using channels like in the original example, we use a boolean flag shouldStop to control when the ticker should stop. After 1600 milliseconds, we set this flag to YES, which causes the ticker to stop on its next iteration.
Note that Objective-C and the iOS/macOS frameworks don’t have a direct equivalent to Go’s ticker, but the combination of GCD’s timer source and dispatch queues provides similar functionality.