title: SwiftUI in target (custom keyboard)
body: <p>Can't find any example of using SwiftUI in Keyboard Extension.
  I create an extension and trying to create simple <code>SwiftUI</code> <code>Button</code> with no action (it just prints debug text). But there is no visible button in Keyboard.
  Is it possible to create SwiftUI custom keyboard?</p>
  <pre><code>struct SwiftUIButton: View{
      let action: () -&gt; ()
      var body: some View{
          Button(action: action){Text(&quot;Tap me&quot;)}
      }
  }
  
  class KeyboardViewController: UIInputViewController {
      
      @IBOutlet var nextKeyboardButton: UIButton!
  
  
  //1.insert this: SwiftUIButton is a simple Button View
      var swiftUIButtonView: SwiftUIButton!
      //...
      override func viewDidLoad() {
          super.viewDidLoad()
          
  
          // Perform custom UI setup here
  
          //2. try to insert my SwiftUI View
          let swiftUIButtonView = SwiftUIButton(action: {print(&quot;test&quot;)})
          let vc = UIHostingController(rootView: swiftUIButtonView)
          //I tried that with no success
          //guard let inputView = inputView else { return }
          //inputView.addSubview(vc.view)
          self.view.addSubview(vc.view)
  
          //all that following code is standard from Xcode
          self.nextKeyboardButton = UIButton(type: .system)
  
          self.nextKeyboardButton.setTitle(NSLocalizedString(&quot;Next Keyboard&quot;, comment: &quot;Title for 'Next Keyboard' button&quot;), for: [])
          self.nextKeyboardButton.sizeToFit()
          self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false
  
          self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
  
          self.view.addSubview(self.nextKeyboardButton)
  
          self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
          self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
      }
  </code></pre>
  <p>When I try to test it in simulator, I see empty Keyboard</p>
  <p><a href="https://i.stack.imgur.com/MKueZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MKueZ.png" alt="enter image description here" /></a></p>
  <p>and some errors in debug console:</p>
  <blockquote>
  <p>2020-01-23 02:07:13.421876+0300 SwiftUIKeyboard[4723:376225] Failed to
  inherit CoreMedia permissions from 4717: (null) 2020-01-23</p>
  <p>02:07:13.460713+0300 SwiftUIKeyboard[4723:375598] [External]
  -[UIInputViewController needsInputModeSwitchKey] was called before a connection was established to the host application. This will produce
  an inaccurate result. Please make sure to call this after your primary
  view controller has been initialized.</p>
  </blockquote>
  <p>last message repeats 6 times.</p>
  <p>What am I doing wrong?
  Or do I need to create UIKit Keyboard View and implement SwiftUI inside of it?</p>