0
votes

I have 3 swift classes, ContentView, LogIn and SignUP. I can t make a boolean var which, let s say, is changing it s value in login.swift, to also announce contentview and signup about the new value.

Bassically, I have account = true, when account became false, i want all 3 classes contentview, login and signup to know that he s value is false now.

Any idea how can I do this? An example with simple 3 views will help me. Thanks a lot!

1
What you looking for is @EnvironmentObject. There are many great tutorials and much Information available online. Example: hackingwithswift.com/quick-start/swiftui/… - KevinP

1 Answers

0
votes

You have 3 view right? ContentView, LogIn and SignUP. For all of those view you need to pass like

SignUP().environmentObject(account)
...
Login().environmentObject(account)

and in Views

struct LoginView: View {
    @EnvironmentObject var account: Bool
    ...
}
struct SignUP: View {
    @EnvironmentObject var account: Bool
    ...
}