🐛 Fixing bug where User data was not properly saved to CoreData

This commit is contained in:
2020-12-22 11:30:41 +01:00
committed by Patrick Müller
parent 46551258e2
commit 63b1e56618
5 changed files with 70 additions and 16 deletions
@@ -34,6 +34,7 @@ struct FirstOpeningSettings: View {
.padding(.horizontal)
Button(action: {
self.settings.isFirstOpening = !self.settings.isFirstOpening
self.saveToCoreData()
}){
Text("Confirm")
.padding()
@@ -47,6 +48,11 @@ struct FirstOpeningSettings: View {
extension FirstOpeningSettings{
func saveToCoreData(){
// Delete old user data
let status = UtilityFunctions.deleteAllCoreDataEntitiesOfType(type: "User")
print("Deleting old user data status: \(status)")
// Insert new user data
let entity = NSEntityDescription.entity(forEntityName: "User", in: PersistenceController.shared.context)!
let user = NSManagedObject(entity: entity, insertInto: PersistenceController.shared.context)
user.setValue(name, forKey: "name")