title: Getting "invalid context" error with UIBezierPath
body: <p>I am trying to make this draw a line where the pan gesture happens. The problem is when I try to use this code</p>
  
  <pre><code>var firstPoint: CGPoint!
  
  var path: UIBezierPath!
  
  @IBAction func panned(gesture: UIPanGestureRecognizer) {
      switch gesture.state {
      case .Began: firstPoint = gesture.locationOfTouch(0, inView: view)
      case .Ended: gesture.cancelsTouchesInView = true
      case .Changed:
          path.moveToPoint(firstPoint)
          path.addLineToPoint(gesture.translationInView(view))
          path.stroke()
      default: break
      }
  }
  </code></pre>
  
  <p>...I get multiple errors which I am not quite sure what to do about.</p>
  
  <pre class="lang-none prettyprint-override"><code>Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSetLineWidth: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSetLineJoin: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSetLineCap: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSetMiterLimit: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextSetFlatness: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  Apr 2 17:40:03 MacBook-Pro.local Paint[6729] &lt;Error&gt;: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
  </code></pre>