SwiftUI Journey Part 5: Sign In To Home View
On iOS, to transition from a SignInViewController
to HomeViewController
after the user successfully signs in, you just have to call the makeKeyAndVisible().
But on macOS using SwiftUI, here’s how I did it. It took me a while to get this right. And, still not entirely sure if this is the way.
Here’s what my sign in view looks like, some parts are removed obviously for security reasons. But the conditional logic is the same.
|
|
First of all, the concept of @State
is still foreign to me. It is both awesome and terrifying. Terrifying because it seems there are no lifecycles to follow and might cause some logic bugs in the future. This needs more serious study but in the meantime, signInSuccess
variable holds the state of whether the user successfully signs in or not.
Now, here’s my sign in function.
|
|
By the time the variable signInSuccess
is set to true, SwiftUI will update the parts of the view heirarchy. That means the condition below will be triggered.
|
|
It’s frustrating how few SwiftUI for macOS tutorials are out there. Anyway, that’s all for now.