title: How to pass object to other view in SwiftUI with core data
body: <p>I am trying to just simple CURD operations with core data in SwiftUI. I have already googling but didn't get succees.</p>
  <p>I have successfully implemented Create operation. Now I am trying to implement the &quot;Edit&quot; operation. for edit operation, I want to pass an object to second view.</p>
  <p>What I am trying:</p>
  <pre><code>//ContentView
  
  struct ContentView: View {
      
      @Environment(\.managedObjectContext) var managedObjectContext
      
      @FetchRequest(entity: StudentCoreData.entity(),sortDescriptors: [])
     
      var students: FetchedResults&lt;StudentCoreData&gt;
      @State var showAddStudentSheet = false
  
      var body: some View {
          
           NavigationView{
              VStack
                  {
                      List {
                          ForEach(self.students, id: \.id) { student in
                              NavigationLink(destination: AddStudent())
                              {
                                  Text(student.name ?? &quot;Unknown&quot;)
                              }
                          }
                      }
              }
              .navigationBarTitle(&quot;students&quot;)
              .navigationBarItems(trailing: Button(action: {
                  //  self.showAddStudentSheet = true
                  self.showAddStudentSheet.toggle()
              }, label: {
                  Text(&quot;Add&quot;)
              }))
                  .sheet(isPresented: $showAddStudentSheet) {
                      AddStudent().environment(\.managedObjectContext, self.managedObjectContext)
              }
              
          }
      }
  }
  
   
  struct ContentView_Previews: PreviewProvider {
      
      static var previews: some View {
          
          let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
          
          return ContentView().environment(\.managedObjectContext, context)
      }
  }
  
  
  //And AddStudent View
  struct AddStudent : View {
      
      @Environment(\.managedObjectContext) var managedObjectContext
      @Environment (\.presentationMode) var presentationMode
      
      @State var studentName = &quot;&quot;
  
      var body: some View
      {
          
          NavigationView
              {
                  Form
                      {
                          
                          Section(content: {
                              
                              Text(&quot;Student Details&quot;)
                                  .font(.headline)
                                  .fontWeight(.medium)
                                  .multilineTextAlignment(.leading)
                                  .padding(.leading, 5.0)
                              TextField(&quot;Name&quot;, text: $studentName)
                                  .padding(.all, 16.0)
                              
                          })
                          
                          
                          Section(content: {
                              Button(action: {
                                  guard self.studentName != &quot;&quot; else {return}
                                  let newOrder = StudentCoreData(context: self.managedObjectContext)
                                  newOrder.name = self.studentName
                                  newOrder.id = UUID()
                                  do {
                                      try self.managedObjectContext.save()
                                      print(&quot;Order saved.&quot;)
                                      self.presentationMode.wrappedValue.dismiss()
                                  } catch {
                                      print(error.localizedDescription)
                                  }
                                  
                              }) {
                                  Text(&quot;Click me&quot;)
                                      .font(.system(size: 18))
                                      .multilineTextAlignment(.center)
                              }
                              .frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
                              
                          })
                  }
                  .navigationBarTitle(&quot;Add Student&quot;)
                  .navigationBarItems(leading:  Button(action: {
                      self.presentationMode.wrappedValue.dismiss()
  
                  }, label: {
                      Text(&quot;Cancel&quot;)
                  }))
          }
          
          
      }
  }
  
  struct AddStudent_Previews: PreviewProvider {
      static var previews: some View {
          AddStudent()
      }
  }
  </code></pre>
  <p>I want to pass student object on click row of the table list.</p>
  <p>I want to know how to pass the variable. How to make this variable on &quot;Add student&quot; view, because if I make a new variable it reflects at all places where AddStudent class called, and then new problems come.</p>
  <p>Please help.</p>