title: Create and display different data after perform a cell selection in UITableView
body: <p>I'm trying to add student name by clicking a button after selecting Class cell in the previous TableView, the problem I'm facing is, for example, I have three classes, class A, B, C. Then I choose class A to create student X, but then when I go back to class B or class C, I also see student X inside those classes. I realized that I use the same data for all classes, but I'm not able to fix this.</p>
  
  <pre><code>import UIKit
  import CoreData
  
  class StudentListViewController: UIViewController, UITableViewDataSource,UITableViewDelegate {
  
  @IBOutlet weak var tableView: UITableView!
  
  var studentList = [StudentData]()
  
  var student: StudentData?
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let fetchRequest: NSFetchRequest&lt;StudentData&gt; = StudentData.fetchRequest()
  
      do {
          let studentList = try PersistenceService.context.fetch(fetchRequest)
          self.studentList = studentList
          self.tableView.reloadData()
      } catch {}
  
  }
  
  @IBAction func addStudentTapped(_ sender: UIBarButtonItem) {
      let alert = UIAlertController(title: "Add Student", message: nil, preferredStyle: .alert)
      alert.addTextField { (studentListTF) in
          studentListTF.placeholder = "Enter name"
      }
      alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
      let action = UIAlertAction(title: "Add", style: .default) { (_) in
          guard let student = alert.textFields?.first?.text else { return }
          print(student)
          let person = StudentData(context: PersistenceService.context)
          person.student_name = student
          PersistenceService.saveContext()
          self.studentList.append(person)
          self.tableView.reloadData()
      }
      alert.addAction(action)
      present(alert,animated: true)
  }
  
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return studentList.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let stuCell = tableView.dequeueReusableCell(withIdentifier: "studentCell", for: indexPath)
  
      stuCell.textLabel?.text = studentList[indexPath.row].student_name
  
      return stuCell
  }
  
  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
      guard editingStyle == .delete else {return}
      let person = studentList[indexPath.row]
      studentList.remove(at: indexPath.row)
      tableView.deleteRows(at: [indexPath], with: .fade)
      PersistenceService.context.delete(person)
      PersistenceService.saveContext()
  
      let fetchRequest: NSFetchRequest&lt;StudentData&gt; = StudentData.fetchRequest()
      do {
          let studentList = try PersistenceService.context.fetch(fetchRequest)
          self.studentList = studentList
      } catch {}
      self.tableView.reloadData()
      print("Delete \(person)")
  }
  
  }
  </code></pre>