title: Change of view in swiftui
body: <p>my swift code below presents two views what I have to do is display the SecondViewController. Swift when tapped on the login button, how can I do it by implementing it in the code below?
  The code of the first view displays a login screen when clicking on the login button I must be push to SecondView.
  I am new to swiftui</p>
  <p><strong>SecondViewController.Swift</strong></p>
  <pre><code>import SwiftUI
  import MapKit
  
  struct HomeView:  View {
      @State private var userTrackingMode: MapUserTrackingMode = .follow
      @State private var region = MKCoordinateRegion(
          center: CLLocationCoordinate2D(
              latitude: 25.7617,
              longitude: 80.1918
          ),
          span: MKCoordinateSpan(
              latitudeDelta: 10,
              longitudeDelta: 10
          )
      )
  
      var body: some View {
          Map(
              coordinateRegion: $region,
              interactionModes: MapInteractionModes.all,
              showsUserLocation: true,
              userTrackingMode: $userTrackingMode
          )
          
      }
  }
  
  struct HomeView_Previews: PreviewProvider {
      static var previews: some View {
          HomeView()
      }
  }
  </code></pre>
  <p><strong>MainView.swift</strong></p>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
      var body: some View {
          
          ZStack{
              
              LinearGradient(gradient: .init(colors: [Color(&quot;Color&quot;),Color(&quot;Color1&quot;),Color(&quot;Color2&quot;)]), startPoint: .top, endPoint: .bottom).edgesIgnoringSafeArea(.all)
              
              if UIScreen.main.bounds.height &gt; 800{
                  
                  Home()
              }
              else{
                  
                  ScrollView(.vertical, showsIndicators: false) {
                      
                      Home()
                  }
              }
          }
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  
  struct Home : View {
      
      @State var index = 0
      @State var showingDetail = false
      @State var isModal: Bool = false
      
      
      
      func login(){
      
      }
      
      var body : some View{
          
          VStack{
              
              Image(&quot;logo&quot;)
              .resizable()
              .frame(width: 200, height: 180)
              
              HStack{
                  
                  Button(action: {
                      
                      withAnimation(.spring(response: 0.8, dampingFraction: 0.5, blendDuration: 0.5)){
                       
                         self.index = 0
                      }
                      
                      
                  }) {
                      
                      Text(&quot;Login&quot;)
                          .foregroundColor(self.index == 0 ? .black : .white)
                          .fontWeight(.bold)
                          .padding(.vertical, 10)
                          .frame(width: (UIScreen.main.bounds.width - 50) / 2).sheet(isPresented: $isModal, content: {
                              
                          })
                      
                  }.background(self.index == 0 ? Color.white : Color.clear)
                  .clipShape(Capsule())
                  
                  Button(action: {
                     withAnimation(.spring(response: 0.8, dampingFraction: 0.5, blendDuration: 0.5)){
                         
                        self.index = 1
                     }
                      
                  }) {
                      
                      Text(&quot;New User&quot;)
                          .foregroundColor(self.index == 1 ? .black : .white)
                          .fontWeight(.bold)
                          .padding(.vertical, 10)
                          .frame(width: (UIScreen.main.bounds.width - 50) / 2)
                      
                  }.background(self.index == 1 ? Color.white : Color.clear)
                  .clipShape(Capsule())
                  
              }.background(Color.black.opacity(0.1))
              .clipShape(Capsule())
              .padding(.top, 25)
              
              if self.index == 0{
                  
                  Login(mail: &quot;&quot;, pass: &quot;&quot;, areYouGoingToSecondView: false)
                  
              }
              else{
                  
                  SignUp()
              }
              
              if self.index == 0{
                  
                  Button(action: {
                      
                  }) {
                      
                      Text(&quot;Forget Password?&quot;)
                          .foregroundColor(.white)
                  
                  }
                  .padding(.top, 20)
              }
              
          }
          .padding()
      }
  }
  
  struct Login : View {
      
      @State var mail = &quot;&quot;
      @State var pass = &quot;&quot;
      @State var areYouGoingToSecondView: Bool=false
      
      var body : some View{
          
          VStack{
              
              VStack{
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;envelope&quot;)
                          .foregroundColor(.black)
                      
                      TextField(&quot;Enter Email Address&quot;, text: self.$mail)
                      
                  }.padding(.vertical, 20)
                  
                  Divider()
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;lock&quot;)
                      .resizable()
                      .frame(width: 15, height: 18)
                      .foregroundColor(.black)
                      
                      SecureField(&quot;Password&quot;, text: self.$pass)
                      
                      Button(action: {
                          
                      }) {
                          
                          Image(systemName: &quot;eye&quot;)
                              .foregroundColor(.black)
                      }
                      
                  }.padding(.vertical, 20)
                  
              }
              .padding(.vertical)
              .padding(.horizontal, 20)
              .padding(.bottom, 40)
              .background(Color.white)
              .cornerRadius(10)
              .padding(.top, 25)
              
      
              
              Button(action: {
                  print(&quot;Prova di stampa&quot;)
              }) {
            
                  Text(&quot;LOGIN&quot;)
                      .foregroundColor(.white)
                      .fontWeight(.bold)
                      .padding(.vertical)
                      .frame(width: UIScreen.main.bounds.width - 100)
                  
                  
              }.background(
              
                  LinearGradient(gradient: .init(colors: [Color(&quot;Color2&quot;),Color(&quot;Color1&quot;),Color(&quot;Color&quot;)]), startPoint: .leading, endPoint: .trailing)
              )
              .cornerRadius(8)
              .offset(y: -40)
              .padding(.bottom, -40)
              .shadow(radius: 15)
          }
      }
  }
  
  struct SignUp : View {
      
      @State var mail = &quot;&quot;
      @State var pass = &quot;&quot;
      @State var checkpass = &quot;&quot;
      @State var repass = &quot;&quot;
      @State var name = &quot;&quot;
      @State var surname = &quot;&quot;
      
      var body : some View{
          
          VStack{
              
              VStack{
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;envelope&quot;)
                          .foregroundColor(.black)
                      
                      TextField(&quot;Enter Email Address&quot;, text: self.$mail)
                      
                  }.padding(.vertical, 20)
                  
                  Divider()
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;person&quot;)
                      .resizable()
                      .frame(width: 15, height: 18)
                      .foregroundColor(.black)
                      
                      TextField(&quot;Enter Name&quot;, text: self.$name)
                      
              
                      
                  }.padding(.vertical, 20)
                  
                  
                  Divider()
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;person&quot;)
                      .resizable()
                      .frame(width: 15, height: 18)
                      .foregroundColor(.black)
                      
                      TextField(&quot;Enter Surname&quot;, text: self.$surname)
                      
              
                      
                  }.padding(.vertical, 20)
                  
                  
                  
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;lock&quot;)
                      .resizable()
                      .frame(width: 15, height: 18)
                      .foregroundColor(.black)
                      
                      SecureField(&quot;Password&quot;, text: self.$pass)
                      
                      Button(action: {
                          
                      }) {
                          
                          Image(systemName: &quot;eye&quot;)
                              .foregroundColor(.black)
                      }
                      
                  }.padding(.vertical, 20)
                  
                  Divider()
                  HStack(spacing: 15){
                      
                      Image(systemName: &quot;lock&quot;)
                      .resizable()
                      .frame(width: 15, height: 18)
                      .foregroundColor(.black)
                      
                      SecureField(&quot;Re-Enter Password&quot;, text: self.$checkpass)
                      
                      Button(action: {
                          
                      }) {
                          
                          Image(systemName: &quot;eye&quot;)
                              .foregroundColor(.black)
                      }
                      
                  }.padding(.vertical, 20)
                  
                
              }
              .padding(.vertical)
              .padding(.horizontal, 20)
              .padding(.bottom, 40)
              .background(Color.white)
              .cornerRadius(10)
              .padding(.top, 25)
              
              
              
              //Button for signup user
              Button(action: {
                  
              }) {
                  
                  Text(&quot;SIGNUP&quot;)
                      .foregroundColor(.white)
                      .fontWeight(.bold)
                      .padding(.vertical)
                      .frame(width: UIScreen.main.bounds.width - 100)
                  
              }.background(
              
                  LinearGradient(gradient: .init(colors: [Color(&quot;Color2&quot;),Color(&quot;Color1&quot;),Color(&quot;Color&quot;)]), startPoint: .leading, endPoint: .trailing)
              )
              .cornerRadius(8)
              .offset(y: -40)
              .padding(.bottom, -40)
              .shadow(radius: 15)
          }
      }
  }
  </code></pre>