title: Swift Change value of Coredata, not create new
body: <p>I am new and dont understand to any objC, and there is no swift tut.</p>
  
  <p>I am doing app for week planing, i have button, that add me to every day 
  -name
  -codeName
  -Task01
  .
  .
  -Task10</p>
  
  <p>but if i want to edit one specific day, with another button, i always delete rest of the days, resp. i create new entity with a lot of nils and only the one day is full of information. here is my ghetto solution but it's not working right, it's working a few times, then it said it has about 512 searchResults.count and start lagging and dont work...</p>
  
  <p>Please help me, how to change value of specific Attributes and dont create new entity</p>
  
  <p>Here is my code for edit tuesday( rest of the week is same as monday, but its long code, so here is only code with monday and tuesday): </p>
  
  <pre><code>func getAndPrintData () {
  
      let fetchRequest: NSFetchRequest&lt;Workout&gt; = Workout.fetchRequest()
  
      do {
          let searchResults = try getContext().fetch(fetchRequest)
          print ("num of results = \(searchResults.count)")
          for works in searchResults as [NSManagedObject] {
  
  
              if let moc = managedObjectContext {
                  let workout = Workout(context: moc)
  
                  workout.mondayNameCD = works.value(forKey: "mondayNameCD") as! String?
                  workout.mondayCodeNameCD = works.value(forKey: "mondayCodeNameCD") as! String?
                  workout.mondayTask01 = works.value(forKey: "mondayTaks01") as! String?
                  workout.mondayTask02 = works.value(forKey: "mondayTaks02") as! String?
                  workout.mondayTask03 = works.value(forKey: "mondayTaks03") as! String?
                  workout.mondayTask04 = works.value(forKey: "mondayTaks04") as! String?
                  workout.mondayTask05 = works.value(forKey: "mondayTaks05") as! String?
                  workout.mondayTask06 = works.value(forKey: "mondayTaks06") as! String?
                  workout.mondayTask07 = works.value(forKey: "mondayTaks07") as! String?
                  workout.mondayTask08 = works.value(forKey: "mondayTaks08") as! String?
                  workout.mondayTask09 = works.value(forKey: "mondayTaks09") as! String?
                  workout.mondayTask10 = works.value(forKey: "mondayTaks10") as! String?
                  workout.tuesdayNameCD = DayName.text!
                  workout.tuesdayCodeNameCD = CodeNameTextField.text!
                  workout.tuesdayFocusCD = IconImageTextField.text!
                  workout.tuesdayTask01 = Task01TextField.text!
                  workout.tuesdayTask02 = Task02TextField.text!
                  workout.tuesdayTask03 = Task03TextField.text!
                  workout.tuesdayTask04 = Task04TextField.text!
                  workout.tuesdayTask05 = Task05TextField.text!
                  workout.tuesdayTask06 = Task06TextField.text!
                  workout.tuesdayTask07 = Task07TextField.text!
                  workout.tuesdayTask08 = Task08TextField.text!
                  workout.tuesdayTask09 = Task09TextField.text!
                  workout.tuesdayTask10 = Task10TextField.text!
              }
          }
      } catch {
          print("Error with request: \(error)")
      }
      saveToCoreData() {
          self.navigationController!.popToRootViewController(animated: true)
      }
  }
  
  func saveToCoreData(completion: @escaping ()-&gt;Void){
      managedObjectContext!.perform {
          do {
              try self.managedObjectContext?.save()
              completion()
              print("Product saved to CoreData")
          } catch let error {
              print("Could not save Product to CoreData: \(error.localizedDescription)")
          }
      }
  }
  
  var managedObjectContext: NSManagedObjectContext? {
      return (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  }
  
  func getContext () -&gt; NSManagedObjectContext {
      let appDelegate = UIApplication.shared.delegate as! AppDelegate
      return appDelegate.persistentContainer.viewContext
  }
  </code></pre>