title: Storing numbers in Core data being reset when saving another page
body: <p>I am storing numbers in Core data that are added in by the user, these are saving fine when I do it, even when I turn the page it saves when I go back to it. But when I save data on another page and then go back it resets all the numbers to 0. </p>
  
  <p>below is my code.</p>
  
  <pre><code>func saveStats() {
  
  
              storeTranscription18CW(pageText: self, textFileUrlString: "") 
  }
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>func storeTranscription18CW (pageText: Any, textFileUrlString: String) {
  
      let context = getContext()
  
      //retrieve the entity that we just created
      let entity =  NSEntityDescription.entity(forEntityName: "TextInputs", in: context)
  
      let CWConvert = Double(CWeight.text!)
  
      let transc = NSManagedObject(entity: entity!, insertInto: context)
          transc.setValue(CWConvert, forKey: "cWeight")
  
  
      //save the object
      do {
          try context.save()
          print("saved!")
      } catch let error as NSError  {
          print("Could not save \(error), \(error.userInfo)")
      } catch {
  
      }
  }
  </code></pre>
  
  <p>and to call</p>
  
  <pre><code>func getTranscriptions18CW () {
      //create a fetch request, telling it about the entity
      let fetchRequest: NSFetchRequest&lt;TextInputs&gt; = TextInputs.fetchRequest()
      do {
          //go get the results
          let searchResults18CW = try getContext().fetch(fetchRequest)
  
              for trans in searchResults18CW as [NSManagedObject] {
                  if let result = trans.value(forKey: "cWeight") {
                      if let str = result as? String {
                          CWeight.text = str
                      }else {
                          CWeight?.text = "\(result)"
                      }
                  }
              }
              //get the Key Value pairs (although there may be a better
      }catch {
          print("Error with request: \(error)")
      }
  }
  </code></pre>
  
  <p>get context function..</p>
  
  <pre><code>func getContext () -&gt; NSManagedObjectContext {
      _ = UIApplication.shared.delegate as! AppDelegate
      return DataController().managedObjectContext
  }
  </code></pre>
  
  <p>here is the function for the other fields when i press save on these the CWeight.text resets to 0...</p>
  
  <pre><code> func savePressed() {
      if indexPageSum == 22 {
          storeTranscription(pageText: self, textFileUrlString: "")
              saveButtonP22.isUserInteractionEnabled = false
              saveButtonP22.alpha = 0.4
  
      }
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>  func storeTranscription (pageText: Any, textFileUrlString: String) {
      let context = getContext()
  
      //retrieve the entity that we just created
      let entity =  NSEntityDescription.entity(forEntityName: "TextInputs", in: context)
  
      let transc = NSManagedObject(entity: entity!, insertInto: context)
  
      //        set the entity values
      if indexPageSum == 22 {
          transc.setValue(page22TextView.text, forKey: "page22")
  
      }
  
      //save the object
      do {
          try context.save()
          print("saved!")
      } catch let error as NSError  {
          print("Could not save \(error), \(error.userInfo)")
      } catch {
  
      }
  }
  </code></pre>
  
  <p>and to call.. </p>
  
  <pre><code>func getTranscriptions () {
      //create a fetch request, telling it about the entity
  
      let fetchRequest: NSFetchRequest&lt;TextInputs&gt; = TextInputs.fetchRequest()
  
      do {
          //go get the results
          let searchResults = try getContext().fetch(fetchRequest)
  
              for trans in searchResults as [NSManagedObject] {
  
                  if indexPageSum == 22{
                      let result22 = trans.value(forKey: "page22")
                      if result22 != nil {
                          page22TextView?.text = result22! as! String
                      }
                  }
  </code></pre>
  
  <p>hopefully this makes sense and you can help.</p>