title: How would I repeat an action forever in Swift?
body: <p><a href="http://i.imgur.com/xkWTk9i.png" rel="noreferrer">http://i.imgur.com/xkWTk9i.png</a>  I already got this rectangle to go from top to bottom. The problem I have is that I want it to repeat every 2 seconds so another rectangle is following it. I want my code to spawn the rectangles every 2 seconds and have it repeat like in flappy bird does with the green pipes. Thank you. (I got this to work before but I deleted my project by mistake and cant figure out how I did it in the first place.) Im in Swift using Spritekit.   </p>
  
  <p>.  </p>
  
  <pre><code> class GameScene: SKScene {
     let sprite = SKSpriteNode(imageNamed: "Rectangle 12")
  
     override func didMoveToView(view: SKView) {
       self.addChild(sprite)
  
        //run doAction function
        doAction()
  
     }
  
  
     //movement of rectangle
  
  
    func createRectangle() {
      let moveToBottom = SKAction.moveByX(0, y: 0 - self.frame.size.width , duration:  
      NSTimeInterval (3.0))
  
      let removeTheNode = SKAction.removeFromParent()
      let moveAndRemovePipes = SKAction.sequence([moveToBottom, removeTheNode])
      let repeatAction = SKAction.repeatActionForever(moveAndRemovePipes)
      sprite.xScale = 1
      sprite.yScale = 1
      sprite.position = CGPoint(x:0,y:0)
      sprite.runAction(repeatAction)
  
  
    }
    //spawn multiple rectangles after 3 or 4 seconds
  
    func doAction() {
      let generateRectangles = SKAction.sequence([
      SKAction.runBlock(self.createRectangle),
      SKAction.waitForDuration(NSTimeInterval(3.0))])
      let endlessAction = SKAction.repeatActionForever(generateRectangles)
      runAction(endlessAction)
    }
  }
  </code></pre>