title: How can I create a sequence of functions and loop them in Swift?
body: <p>I am trying to build a feature so that when you shake the iPhone, the particles on the screen will fly around.</p>
  
  <p>I have hooks to tie into when the shaking begins and ends.</p>
  
  <p>I will create a UIPushBehavior and add it to the animator scene when shaking begins and when it ends I will remove the UIPushBehavior from the animator. </p>
  
  <p>But to get a good shaking experience I want to vary the push angle while the device is in motion. </p>
  
  <p>How can I recreate this pseudo code in Swift?</p>
  
  <pre><code>override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent!)
  {
      if (motion == UIEventSubtype.MotionShake)
      {
          self.push = UIPushBehavior()
          self.push!.angle = -self.angle!
          self.animator.addBehavior(self.push)
          // BEGIN Pseudo Code
          self.sequence = Sequence({self.push.angle = self.angle!}, {self.push.angle = -self.angle}, 
          delay: 100ms)
         // END Pseudo Code
      }
  }
  
  override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!)
  {
      if (motion == UIEventSubtype.MotionShake)
      {
  
         self.animator.removeBehavior(self.push)
         // BEGIN Pseudo Code
         self.sequence.stopSequence()
         // END Pseudo Code
      }
  }
  </code></pre>
  
  <p>So as you can see I want to be able to define 2 functions (which change the direction of push angle by 180 degrees) to be looped every 100ms, until I call stopSequence()</p>
  
  <p>How can I actually do this with Swift?</p>