SwiftUI Toggle changing state when entering background

Viewed 36

I have a view with a list and inside the list there is a toggle that is binded with a boolean in the viewmodel, if I turn on the toggle the boolean is true and viceversa, the issue here is that if I turn on the toggle, and then enter background when I reopen the app, the toggle appears turned off even when the boolean is true, then I go back to the previous screen and when I return to the screen with the toggle it appears turned on, is there a way to avoid this issue? here is the List code below:

List {
        Section(header: Text("Flags")) {
            ForEach(viewModel.flags.indices, id: \.self) { index in
                Toggle(isOn: $viewModel.flags[index].isActive) {
                    Text(viewModel.flags[index].name.rawValue.camelCaseToCapitalized())
                }
            }
        }
0 Answers
Related