SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func saveData() {
  2.         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return}
  3.        
  4.         let managedContext = appDelegate.persistentContainer.viewContext
  5.        
  6.         let userEntity = NSEntityDescription.entity(forEntityName: "Data", in: managedContext)!
  7.        
  8.         let user = NSManagedObject(entity: userEntity, insertInto: managedContext)
  9.        
  10.         user.setValue(answers?.id, forKeyPath:"id")
  11.         user.setValue(answers?.dob, forKeyPath:"dob")
  12.         user.setValue(answers?.q1Experience, forKeyPath:"q1Experience")
  13.         user.setValue(answers?.q2Activity, forKeyPath:"q2Activity")
  14.         user.setValue(answers?.q3Usability, forKeyPath:"q3Usability")
  15.         user.setValue(answers?.q4Future, forKeyPath:"q4Future")
  16.         user.setValue(answers?.longitude, forKey: "longitude")
  17.         user.setValue(answers?.latitude, forKey: "latitude")
  18.        
  19.        
  20.        
  21.         //debugging code, prints to console if save data is successful or not
  22.         do {
  23.             try managedContext.save()
  24.             print ("Answers saved to core data")
  25.         } catch let error as NSError {
  26.             print ("Could not save results. \(error), \(error.userInfo)")
  27.         }
  28.     }
  29.    
  30.    
  31.     /*
  32.     // MARK: - Navigation
  33.  
  34.     // In a storyboard-based application, you will often want to do a little preparation before navigation
  35.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  36.         // Get the new view controller using segue.destination.
  37.         // Pass the selected object to the new view controller.
  38.     }
  39.     */
  40.    
  41.    
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top