title: How to draw UIBezierPath on CALayer in Swift?
body: <p>Currently I do it like this:</p>
  
  <pre><code>    for (_, values) in data {
  
          let layer = CAShapeLayer()
          let path = UIBezierPath()
  
          path.move(to: CGPoint(x: leftOffset, y: bottomOffset - values.first! * scale))
  
          for index in 1..&lt;values.count {
              path.addLine(to: CGPoint(x: leftOffset + widthForMonth * CGFloat(index), y: bottomOffset - values[index] * scale))
          }
  
          colors[currentIndex].set()
          UIColor.clear.setFill()
          path.lineWidth = 2
          path.stroke()
  
          layer.path = path.cgPath
          self.layer.addSublayer(layer)
          currentIndex += 1
      }
  </code></pre>
  
  <p>but the result is unexpected:</p>
  
  <p><a href="https://i.stack.imgur.com/mgDZql.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mgDZql.png" alt="enter image description here"></a></p>
  
  <p>Before I setup a <code>CALayer</code> it was like this:</p>
  
  <p><a href="https://i.stack.imgur.com/zUUwwl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zUUwwl.png" alt="enter image description here"></a></p>
  
  <p>What is wrong here? I really need this on CALayer, because I need hide or unhide it at any time later.</p>