title: Better performance of UIBezierPath drawing iOS Swift ?
body: <p>In my app I'm doing some drawing, but the way I'm doing it is very inefficient and updating the view takes long time. I'm just curious of there is a better way to achieve this. The image and the code are below. </p>
  
  <p>Any kind of help is highly appreciated.</p>
  
  <p><a href="https://i.stack.imgur.com/nBbRn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nBbRn.png" alt="enter image description here"></a></p>
  
  <pre><code>func drawDialWithCurrentValue(  currentValue:CGFloat, andNewValue newValue:CGFloat)
  {
      let radius = 500.0
  
      let circlePath = UIBezierPath(arcCenter: CGPoint(x: 0,y: radius),
                                    radius: CGFloat(radius),
                                    startAngle: CGFloat(0),
                                    endAngle:CGFloat(M_PI * 2),
                                    clockwise: true)
  
  
      let shapeLayer = CAShapeLayer()
      shapeLayer.path = circlePath.CGPath
  
      shapeLayer.fillColor = UIColor.blueColor().CGColor
  
      shapeLayer.strokeColor = UIColor.blueColor().CGColor
  
      shapeLayer.lineWidth = 3.0
  
      drawView.layer.addSublayer(shapeLayer)
  
      let x0 = 0.0
      let y0 = radius
  
      var x1 = x0
      var y1 = y0
  
      var degsInRadians = 0.0
  
      for var index = 0; index &lt; 360; index++
      {
          if index%2 == 0
          {
              degsInRadians = Double(index) * (M_PI/180)
  
              x1 = x0 + radius * cos(degsInRadians)
              y1 = y0 + radius * sin(degsInRadians)
  
  
              let linePath = UIBezierPath()
  
              linePath.moveToPoint(CGPoint( x: x1, y: y1))
  
              linePath.addLineToPoint(CGPoint( x:0, y:radius))
  
              let shapeLayerLine = CAShapeLayer()
              shapeLayerLine.path = linePath.CGPath
  
              shapeLayerLine.fillColor = UIColor.clearColor().CGColor
  
              shapeLayerLine.strokeColor = UIColor.greenColor().CGColor
  
              shapeLayerLine.lineWidth = 3.0
  
              drawView.layer.addSublayer(shapeLayerLine)
          }
      }
  
      let innerCirc = UIBezierPath(arcCenter: CGPoint(x: 0,y: radius),
          radius: CGFloat(radius - 100),
          startAngle: CGFloat(0),
          endAngle:CGFloat(M_PI * 2),
          clockwise: true)
  
  
      let shapeLayer2 = CAShapeLayer()
      shapeLayer2.path = innerCirc.CGPath
  
      shapeLayer2.fillColor = UIColor.blueColor().CGColor
  
      shapeLayer2.strokeColor = UIColor.blueColor().CGColor
  
      shapeLayer2.lineWidth = 3.0
  
      drawView.layer.addSublayer(shapeLayer2)
  }
  </code></pre>