title: fixing - Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
body: <p>I am new to coding and have been trying to make an area on the screen that I can sign with my finger. I have made the box but I am struggling to clear it. I have made a button connected to a function to clear the path but I can't seem to work out how to safely unwrap the information without it crashing. </p>
  
  <pre><code>import UIKit
  
  class canvasView: UIView {
  
      var lineColour:UIColor!
      var lineWidth:CGFloat!
      var path:UIBezierPath!
      var touchPoint:CGPoint!
      var startingPoint:CGPoint!
  
  
      override func layoutSubviews() {
          self.clipsToBounds = true
          self.isMultipleTouchEnabled = false
  
          lineColour = UIColor.white
          lineWidth = 10
      }
  
      override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          let touch = touches.first
          startingPoint = (touch?.location(in: self))!
      }
  
      override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          let touch = touches.first
          touchPoint = touch?.location(in: self)
  
          path = UIBezierPath()
          path.move(to: startingPoint)
          path.addLine(to: touchPoint)
          startingPoint = touchPoint
  
          drawShapelayer()
      }
      func drawShapelayer(){
          let shapeLayer = CAShapeLayer()
          shapeLayer.path = path.cgPath
          shapeLayer.strokeColor = lineColour.cgColor
          shapeLayer.lineWidth = lineWidth
          shapeLayer.fillColor = UIColor.clear.cgColor
          self.layer.addSublayer(shapeLayer)
          self.setNeedsDisplay()
      }
  
      func clearCanvas() {
          path.removeAllPoints()
          self.layer.sublayers = nil
          self.setNeedsDisplay()
      }
  </code></pre>
  
  <p>I then get the error in my final function after </p>
  
  <pre><code>path.removeAllPoints()
  </code></pre>
  
  <p>How is best to unwrap it to stop it crashing?</p>
  
  <p>Thank you for your patience</p>