Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func saveData() {
- guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return}
- let managedContext = appDelegate.persistentContainer.viewContext
- let userEntity = NSEntityDescription.entity(forEntityName: "Data", in: managedContext)!
- let user = NSManagedObject(entity: userEntity, insertInto: managedContext)
- user.setValue(answers?.id, forKeyPath:"id")
- user.setValue(answers?.dob, forKeyPath:"dob")
- user.setValue(answers?.q1Experience, forKeyPath:"q1Experience")
- user.setValue(answers?.q2Activity, forKeyPath:"q2Activity")
- user.setValue(answers?.q3Usability, forKeyPath:"q3Usability")
- user.setValue(answers?.q4Future, forKeyPath:"q4Future")
- user.setValue(answers?.longitude, forKey: "longitude")
- user.setValue(answers?.latitude, forKey: "latitude")
- //debugging code, prints to console if save data is successful or not
- do {
- try managedContext.save()
- print ("Answers saved to core data")
- } catch let error as NSError {
- print ("Could not save results. \(error), \(error.userInfo)")
- }
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement