I have an edit profile page that has a done button which uses .PopViewController after storing all the new information in CoreData. However, the profile/coredata does not update as it should unless I completely close the app and reopen it.
@IBAction func doneEditing(_ sender: Any) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Profile", in: context)
let newProfile = NSManagedObject(entity: entity!, insertInto: context)
newProfile.setValue(userFavMeal.text, forKey: "favMeal")
newProfile.setValue(userRestaurant.text, forKey: "favRest")
newProfile.setValue(userAllergies.text, forKey: "allergies")
newProfile.setValue(gradYear.text, forKey: "gradYear")
do {
try context.save()
} catch {
print("Error - CoreData Saving Failed")
}
self.navigationController?.popViewController(animated: true)
}
Could someone help me figure out how to have the data instantly refresh? I tried instantiating a new ViewController upon clicking the done button but that caused problems with constraints (although it worked).