title: Referring to a json array file for swiftui
body: <p>I am trying to write code so that each time the confirm answer button is clicked, the next question in the json array is called. There are five questions in this file and so far I can get the first and second question to appear. Is there anyway I could write a loop so that the next question is called each time the user enters confirm?
  I am new to swiftui and so am unsure about how to proceed</p>
  <pre><code>import SwiftUI
  struct SecondView: View {
  
  var ResearchMCQ: Question
  
  
  //Creating Variables for Revision Topics
  @State private var setOptionOne = false
  @State private var setOptionTwo = false
  @State private var setOptionThree = false
      
  let button = [&quot;Confirm Answer&quot;]
  @State public var buttonConfirm: Int?
  
          var body: some View {
  
          ScrollView{
              
              VStack(spacing: 1.0) {
     
   Group {
      Text(ResearchMCQ.question)
      .padding(.trailing, 5)
      
  
  //Ensures Only One Answer Can Be Selected
          let OptionOne = Binding&lt;Bool&gt;(get: { self.setOptionOne }, set: { self.setOptionOne = $0; self.setOptionTwo = false; self.setOptionThree = false })
          let OptionTwo = Binding&lt;Bool&gt;(get: { self.setOptionTwo }, set: { self.setOptionOne = false; self.setOptionTwo = $0; self.setOptionThree = false })
          let OptionThree = Binding&lt;Bool&gt;(get: { self.setOptionThree }, set: { self.setOptionOne = false; self.setOptionTwo = false; self.setOptionThree = $0 })
  
  
          VStack {
              Toggle(ResearchMCQ.options[0], isOn: OptionOne)
                  .toggleStyle(.button)
                  .tint(Color(.gray))
                  .foregroundColor(Color(&quot;Black-White&quot;))
              Toggle(ResearchMCQ.options[1], isOn: OptionTwo)
                  .toggleStyle(.button)
                  .tint(Color(.gray))
                  .foregroundColor(Color(&quot;Black-White&quot;))
              Toggle(ResearchMCQ.options[2], isOn: OptionThree)
                  .toggleStyle(.button)
                  .tint(Color(.gray))
                  .foregroundColor(Color(&quot;Black-White&quot;))
                   }
      }
                  
                  Spacer()
                  Spacer()
                  
                  HStack(spacing: 15) {
                  ForEach(0..&lt;button.count, id: \.self) {button in
                          Button(action: {
                              self.buttonConfirm = button
                              
                          }) {
                              
      //Links Continue Button To Next Page
                              NavigationLink(destination: SecondView(ResearchMCQ: questions[1])) {
                                  Text(&quot;Confirm Answer&quot;)
                                  
                              }
                              
                              .padding(.vertical, 12.5)
                              .padding(.horizontal, 120)
                              .foregroundColor(.white)
                              .foregroundStyle(.background)
                              .background(2 == button ? Color.primary: Color.secondary)
                              .clipShape(Capsule())
                      
                      
                  }
                  
                  
          }
      }
  }
              
  
     .navigationTitle(&quot;&quot;)
              
          }
  
  }
  
          }
  
  
  struct SecondView_Previews: PreviewProvider {
  static var previews: some View {
      SecondView(ResearchMCQ: questions[0])
  
  }
  </code></pre>
  <p>}</p>