title: swiftui - how to avoid 'Unable to simultaneously satisfy constraints' error?
body: <p>I am trying to apply the code in the accepted answer to <a href="https://stackoverflow.com/questions/56507839/swiftui-how-to-make-textfield-become-first-responder">this</a> question, on how to make a SwiftUI TextField become a first responder. Here is the code, copied from that answer, which I tried to use in xcode:</p>
  <pre><code>struct CustomTextField: UIViewRepresentable {
  
      class Coordinator: NSObject, UITextFieldDelegate {
  
          @Binding var text: String
          var didBecomeFirstResponder = false
  
          init(text: Binding&lt;String&gt;) {
              _text = text
          }
  
          func textFieldDidChangeSelection(_ textField: UITextField) {
              text = textField.text ?? &quot;&quot;
          }
  
      }
  
      @Binding var text: String
      var isFirstResponder: Bool = false
  
      func makeUIView(context: UIViewRepresentableContext&lt;CustomTextField&gt;) -&gt; UITextField {
          let textField = UITextField(frame: .zero)
          textField.delegate = context.coordinator
          return textField
      }
  
      func makeCoordinator() -&gt; CustomTextField.Coordinator {
          return Coordinator(text: $text)
      }
  
      func updateUIView(_ uiView: UITextField, context: UIViewRepresentableContext&lt;CustomTextField&gt;) {
          uiView.text = text
          if isFirstResponder &amp;&amp; !context.coordinator.didBecomeFirstResponder  {
              uiView.becomeFirstResponder()
              context.coordinator.didBecomeFirstResponder = true
          }
      }
  }
  </code></pre>
  <p>Running that code, however, gives me a run-time error, saying 'Unable to simultaneously satisfy constraints.' The error is shown below.</p>
  <blockquote>
  <p>in makeUIView</p>
  <p>in updateUIView in onEditingChanged 2020-08-14 16:02:48.445045-0600
  OpenRussian[2965:122005] [LayoutConstraints] Unable to simultaneously
  satisfy constraints.  Probably at least one of the constraints in the
  following list is one you don't want.     Try this:       (1) look at each
  constraint and try to figure out which you don't expect;          (2) find
  the code that added the unwanted constraint or constraints and fix it.
  (
  &quot;&lt;NSLayoutConstraint:0x600002580d20 'assistantHeight' TUISystemInputAssistantView:0x7fde585064a0.height == 44   (active)&gt;&quot;,
  &quot;&lt;NSLayoutConstraint:0x600002591b30 'assistantView.bottom' TUISystemInputAssistantView:0x7fde585064a0.bottom ==
  _UIKBCompatInputView:0x7fde51b78c50.top   (active)&gt;&quot;,
  &quot;&lt;NSLayoutConstraint:0x600002591ae0 'assistantView.top' V:|-(0)-[TUISystemInputAssistantView:0x7fde585064a0]   (active, names:
  '|':UIInputSetHostView:0x7fde58518070 )&gt;&quot;,
  &quot;&lt;NSLayoutConstraint:0x600002591720 'inputView.top' V:|-(0)-[_UIKBCompatInputView:0x7fde51b78c50]   (active, names:
  '|':UIInputSetHostView:0x7fde58518070 )&gt;&quot; )</p>
  <p>Will attempt to recover by breaking constraint
  &lt;NSLayoutConstraint:0x600002591b30 'assistantView.bottom'
  TUISystemInputAssistantView:0x7fde585064a0.bottom ==
  _UIKBCompatInputView:0x7fde51b78c50.top   (active)&gt;</p>
  <p>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints
  to catch this in the debugger. The methods in the
  UIConstraintBasedLayoutDebugging category on UIView listed in
  &lt;UIKitCore/UIView.h&gt; may also be helpful.</p>
  </blockquote>
  <p>What can I modify to make this work, and avoid this 'unable to simultaneously satisfy constraints' run-time error?</p>