title: Smooth animation with timer and loop in iOS app
body: <p>I have ViewController with stars rating that looks like this (except that there are 10 stars)</p>
  
  <p><a href="https://i.stack.imgur.com/Dqf6j.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dqf6j.jpg" alt="enter image description here"></a></p>
  
  <p>When user opens ViewController for some object that have no rating I want to point user's attention to this stars with very simple way: animate stars highlighting (you could see such behaviour on some ads in real world when each letter is highlighted one after another).  </p>
  
  <ol>
  <li>One star highlighted </li>
  <li>Two stars highlighted </li>
  <li>Three stars highlighted</li>
  <li>......</li>
  <li>Turn off all of them</li>
  </ol>
  
  <p>So this is the way how I am doing it</p>
  
  <pre><code>func delayWithSeconds(_ seconds: Double, completion: @escaping () -&gt; ()) {
      DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
          completion()
      }
  } 
  
  func ratingStarsAnimation() {
      for i in 1...11 {
          var timer : Double = 0.6 + Double(i)*0.12
          delayWithSeconds(timer) {
              ratingStars.rating = (i &lt; 10) ? Double(i) : 0
          }
      }
  }
  </code></pre>
  
  <p>What is going on here? I have function called delayWithSeconds that delays action and I use this function to delay each star highlighting. And 0.6 is initial delay before animation begins. After all stars are highlighted - last step is to turn off highlighting of all stars.
  This code works but I can't say that it is smooth.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li>How can I change 0.6 + Double(i)*0.12 to get smooth animation feel?</li>
  <li>I think that my solution with delays is not good - how can I solve smooth stars highlighting task better?</li>
  </ol>