Cannot update view

The variable from SignInController changes, the view does not.

import SwiftUI
import Foundation

class SignInController: ObservableObject {
    var signedIn: Bool = false
}

struct MainView: View {
    
    @StateObject var signCon = SignInController()
    
    var body: some View {
        return Group {
            if signCon.signedIn == false {
                ZStack {
                    SignView()
                    Button {
                        signCon.signedIn.toggle()
                        print(signCon.signedIn)
                    } label: {
                        Text("Make True")
                    }
                }
            }
            else if signCon.signedIn == true {
                HomeView()
            }
        }
    }
    
}

struct MainView_Previews: PreviewProvider {
    static var previews: some View {
        MainView()
    }
}


extension UserDefaults {

    func valueExists(forKey key: String) -> Bool {
        return object(forKey: key) != nil
    }

}
Answered by robnotyou in 698699022

Try

class SignInController: ObservableObject {
    @Published var signedIn: Bool = false
}

(By the way, in MainView, I think your ZStack should be a VStack)

Accepted Answer

Try

class SignInController: ObservableObject {
    @Published var signedIn: Bool = false
}

(By the way, in MainView, I think your ZStack should be a VStack)

Cannot update view
 
 
Q