I want to save the data in the database profileDB.lvl that is transferred from another property self.lvl
At the beginning of ContentView I prescribed:
@Environment(\.managedObjectContext) var managedObjectContext
And
@State public var lvl = 0
let profileDB = ProfileUser(context: self.managedObjectContext)
Then, in the button below, I prescribed the logic of saving:
Button(action: {
withAnimation(.easeInOut){
profileDB.lvl = Int16(self.lvl)
do{
if progress < 300{
progress += 75
} else if progress == 300{
progress = 50
self.lvl += 1
}
try self.managedObjectContext.save()
} catch{
print(error)
}
}
},
label: {
Text("Perform")
.foregroundColor(Color.black)
.font(.system(size: 18, design: .default))
})
And it turns out that the data is changed in self.lvl, but not assigned to profileDB.lvl
Am I having trouble with the correct implementation, what can help solve the problem?