title: Counting From X to Y - UILabel - CADisplayLink
body: <p>I've implemented a Counting - Label which counts from x to y by a given period of time. Hovewever, I use a <code>UILabel</code> and and a <code>CADisplayLink</code> to update the text of the `UILabel.</p>
  
  <p>Now, I assume the problem is, that "something" blocks the main thread for a short period of time which ends up, that the "Counting-Animation" looks not very smooth. This means if counting from -2650 to 4000 - it's stops at 2000 by a really short period of time (but long enough to get noticed by the user) and continous afterwards..</p>
  
  <p>My Code looks like:</p>
  
  <pre><code>// Create the display link and add it to the runloop -&gt; commonModes
  let displayLink = CADisplayLink(target: self, selector:#selector(CountAnimator.tick))
  displayLink.isPaused = true
  displayLink.add(to: .main, forMode: .commonModes)
  
  // Update the text of the label (just assume that there is a non time expensive function which calculates the current count)
  fileprivate func tick() {
    self.textLabel.text = currentCount
  }
  </code></pre>
  
  <p>I know that it would be the best to find the source why the main-thrad is blocked (Instruments), however imagine that this would be really hard to find and the counter animation has to be work in a smooth way.</p>
  
  <p>Do you have an idea how this counting animation could be done in another way? With Core Animation, <code>CATextLayer</code> animation etc. (knowing that the update of the UILabel.text has to be on the main thread)? Do you think the problem could be that anything else blocks the main thread?</p>
  
  <p>P.s. The Counting animation looks like the "Stop-Watch" in Apples' Watch App.</p>
  
  <p>thx</p>