title: Swift draw several paths in loops
body: <p>I'm working on changing my previously circlechart, to a donutchart (That can support more than 1 number).</p>
  <p>I got all the angle's correct, changed my data to work with an array.</p>
  <p>But when I try to draw my paths, it only draws the last one.</p>
  <p>Here's an example screenshot of the issue:</p>
  <p><img src="https://i.stack.imgur.com/QelHI.png" alt="enter image description here" /></p>
  <p>In the above example, it's set to draw this array:</p>
  <pre><code>cell.circleChart.percentFills = [weight, 10]
  </code></pre>
  <p>where weight is the % shown in the label of the circle. So you can see, that it doesn't draw the first angle, but the starting point for the next angle is correct.</p>
  <p>Here's the code where I draw my donut chart.</p>
  <pre><code>    override func drawRect(rect: CGRect) {
      // Define the center.
      let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
      
      // Define the radius
      let radius: CGFloat = max(bounds.width, bounds.height)
      
      // Define starting and ending angles
      var startAngle: CGFloat = CGFloat(DegreesToRadians(-90))
      let endAngle: CGFloat = CGFloat(DegreesToRadians(270))
      
      // Set up the full path. (for the default background color)
      var path = UIBezierPath(arcCenter: center,
          radius: bounds.width/2 - arcWidth/2,
          startAngle: startAngle,
          endAngle: endAngle,
          clockwise: true)
  
      // draw the full chart with the background color
      path.lineWidth = arcWidth
      chartColor.setStroke()
      path.stroke()
      
      //calculate the arc for each per percent
      let arcLengthPerPercent = CGFloat(DegreesToRadians(360/100))
  
      // Temporary var for loop testing
      var i = 0
      
      println(&quot;startAngle before loop: \(RadiansToDegrees(Double(startAngle)))&quot;)
      
      for percentFill in percentFills {
          
          println(&quot;LOOP: \(i)&quot;)
          
          if i == 0 {
              fillColor = UIColor.formulaBlueColor()
              println(&quot;BLUE&quot;)
          } else {
              fillColor = UIColor.formulaGreenColor()
              println(&quot;GREEN&quot;)
          }
          
          //then multiply out by the actual percent
          let fillEndAngle = arcLengthPerPercent * CGFloat(percentFill) + startAngle
          
          println(&quot;fillEndAngle: \(RadiansToDegrees(Double(fillEndAngle)))&quot;)
          
          //2 - draw the outer arc
          var fillPath = UIBezierPath(arcCenter: center,
              radius: bounds.width/2 - arcWidth/2,
              startAngle: startAngle,
              endAngle: fillEndAngle,
              clockwise: true)
          
          progressLine.path = fillPath.CGPath
          progressLine.strokeColor = fillColor.CGColor
          progressLine.fillColor = UIColor.clearColor().CGColor
          progressLine.lineWidth = arcWidth
          
          // add the curve to the screen
          self.layer.addSublayer(progressLine)
          
          i++
          startAngle = startAngle+(arcLengthPerPercent * CGFloat(percentFill))
      }
      
  }
  </code></pre>
  <p>I reckon I'm probably going wrong in the last bit, where I add the progressLine as a subLayer, but I don't know what else I should be doing here instead.</p>
  <p>Of course I've tested that if I only have 1 value in the array, it draws that as intended (in the blue color)</p>
  <p>Any help getting several paths drawn out, would be greatly appreciated!</p>