title: SwiftUI - Textfield return key event
body: <p>First of all, I'm sorry that my English is not perfect.</p>
  <p>I want to show a different image depending on the condition of the value received through the return key in the Textfield. I searched and tried several ways, but couldn't find the right way. I couldn't find a proper retrurn key event in SwiftUI, so I tried onReceive.</p>
  <p>swift file.</p>
  <pre><code>struct QuestionItemView: View {
  
      @State private var question: Question?
      @State private var answer = &quot;&quot;
  
      var body: some View {
          VStack(spacing: 30) {
              GroupBox {
                  if let question = question {
                      Text(question.question)
                          .font(.largeTitle)
                          .fontWeight(.heavy)
                          .scaledToFit()
                          .frame(width: 300, height: 100)
                          .cornerRadius(12)
                  }
              }
          
              GroupBox {
                  TextField(&quot;Enter your answer&quot;, text: $answer)
                      .frame(width: 300)
                      .font(.title2)
                      .scaledToFit()
                      .cornerRadius(12)
                      .multilineTextAlignment(.center)
             }
           
              onReceive(answer.publisher) { _ in
                  if answer == question?.answer {
  //                        Image(systemName: &quot;circle&quot;)
                      print(&quot;o&quot;)
                  } else {
  //                        Image(systemName: &quot;multiply&quot;)
                      print(&quot;x&quot;)
                  }
              }
          } //: VStack
          .frame(width: 240)
          .background(RoundedRectangle(cornerRadius: 7.0).fill(Color.white))
          .onAppear {
              let questions: [Question] = Bundle.main.decode(&quot;questions.json&quot;)
              question = questions.randomElement()
          }
      }
  }
  </code></pre>
  <p>json.file</p>
  <pre><code>[
      {
          &quot;id&quot; : 1,
          &quot;question&quot; : &quot;2 X 6&quot;,
          &quot;answer&quot; : &quot;12&quot;
      },
      {
          &quot;id&quot; : 2,
          &quot;question&quot; : &quot;7 + 8&quot;,
          &quot;answer&quot; : &quot;15&quot;
      },
      {
          &quot;id&quot; : 3,
          &quot;question&quot; : &quot;9 - 1&quot;,
          &quot;answer&quot; : &quot;8&quot;
      },
      {
          &quot;id&quot; : 4,
          &quot;question&quot; : &quot;4 / 2&quot;,
          &quot;answer&quot; : &quot;2&quot;
      },
      {
          &quot;id&quot; : 5,
          &quot;question&quot; : &quot;10 X 2&quot;,
          &quot;answer&quot; : &quot;20&quot;
      }
  ]
  </code></pre>