title: How to set a SwiftUI View as a first responder manually?
body: <p>I'm building an app using mostly SwiftUI, but I have to use a UIKit ViewController to interface with PencilKit. I'm using <code>UIViewControllerRepresentable</code> to interface between them.</p>
  
  <p>So I have a ViewController which I'm using to set up the PencilKit part of my app, and inside it I have to set a PKToolPicker which depends on a UIResponder. To do so I have to write the following code:</p>
  
  <pre class="lang-swift prettyprint-override"><code>canvasView = PKCanvasView(frame: view.bounds)
  toolPicker.setVisible(true, forFirstResponder: canvasView)
  canvasView.becomeFirstResponder()
  </code></pre>
  
  <p>This canvasView view I use here is the view which controls the drawing area, and you usually have to set it as a subview of the aforementioned ViewController. The issue is that in my case, this ViewController is nested inside a <code>UIViewControllerRepresentable</code> which is nested inside a SwiftUI View. So, I need to add this SwiftUI view as a second FirstResponder or else the PKTool disappears each time I run a gesture on an SwiftUI view, as canvasView stops being first responder.</p>
  
  <p>So my question is how do I do this? How can I set up a SwiftUI view as a first responder? Couldn't find how to obtain a SwiftUI's UIResponder object though so I could add it as a FirstResponder, anyone know how to?</p>