ios – SwiftUI: The issue is saving knowledge in CoreData

I wish to save the info within the database profileDB.lvl that’s transferred from one other property self.lvl

In the beginning of ContentView I prescribed:

@Setting(.managedObjectContext) var managedObjectContext


@State public var lvl = 0
let profileDB = ProfileUser(context: self.managedObjectContext)

Then, within the button beneath, I prescribed the logic of saving:

Button(motion: {

        profileDB.lvl = Int16(self.lvl)

            if progress < 300{
                progress += 75
            } else if progress == 300{
                progress = 50
                self.lvl += 1
        } catch{
       label: {
    Textual content("Carry out")
        .font(.system(dimension: 18, design: .default))

And it seems that the info is modified in self.lvl, however not assigned to profileDB.lvl
Am I having bother with the right implementation, what might help resolve the issue?

Leave a Reply