title: How to stop a Function from Running in Swift 3.0
body: <p>I have a function that starts playing an animation that is running asynchronously (in the background). This animation is called indefinitely using a completion handler (see below).  Is there a way to close this function upon pressing another button?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>func showAnimation() {
      UIView.animate(withDuration: 1, animations: {
          animate1(imageView: self.Anime, images: self.animation1)
      }, completion: { (true) in
          DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
              self.showAnimation() // replay first showAnimation
          }
      }) 
   }
  </code></pre>
  
  <p>Then upon pressing another button we closeout the above function</p>
  
  <pre><code>showAnimation().stop();
  </code></pre>
  
  <p>Thanks</p>