title: How to wait until an animation is finished in Swift?
body: <p>I try to let a button "shake" before the next question of my quiz is going to load.</p>
  
  <p>The animation looks like </p>
  
  <pre><code>var timer = NSTimer()
      UIView.animateWithDuration(0.1, animations: {
          self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
      })
      UIView.animateWithDuration(0.2, animations: {
          self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x - 4, self.IMGVIEWcat.center.y)
      })
      UIView.animateWithDuration(0.3, animations: {
              self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
      })
  </code></pre>
  
  <p>After this the following function is called</p>
  
  <pre><code>    func QueryInformations(){
          println("QueryInformationsStart")
          self.ActivityIndicator.hidden = false
          ObjectIDsArrayCount = ObjectIDsArray.count
          var RandomQuestion = Int(arc4random_uniform(ObjectIDsArray.count + 0))
          var QuestionID:String = ObjectIDsArray[RandomQuestion]
          var query : PFQuery = PFQuery(className: "AddonQuiz")
          query.getObjectInBackgroundWithId(QuestionID){
              (ObjectHolder : PFObject!, error : NSError!) -&gt; Void in
  ...
  </code></pre>
  
  <p>Now the animation starts but instant the next question is loaded, is there some easy wait for a beginner to implement a "waiting" until the animation is done?</p>
  
  <p>I tried to set</p>
  
  <pre><code>var complet == true 
  </code></pre>
  
  <p>In the animation</p>
  
  <p>And in the query function</p>
  
  <pre><code>if complet = true {....
  </code></pre>
  
  <p>But this did not work for me, also I found some information about completion handler but didn't get it work in my code.</p>