Created
March 29, 2022 07:33
-
-
Save barrault01/4572744542b6def50192c4593d899a75 to your computer and use it in GitHub Desktop.
A simple signup view to demonstrating the benefits of CombineLatest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import Combine | |
struct ContentView: View { | |
@ObservedObject var user = User() | |
var body: some View { | |
VStack { | |
HStack { | |
Text("Username:") | |
TextField("", text: $user.username) | |
.textFieldStyle(.roundedBorder) | |
} | |
.padding() | |
HStack { | |
Text("Password:") | |
SecureField("", text: $user.password) | |
.textFieldStyle(.roundedBorder) | |
} | |
.padding() | |
Toggle("Protect with Face ID", isOn: $user.protectWithTouchID) | |
.padding() | |
} | |
.onReceive( | |
Publishers.CombineLatest3(user.$username, | |
user.$password, | |
user.$protectWithTouchID)) { value in | |
// here you can do what you want with the value | |
// you will receive a tuple like this($username, $password, $protectWithTouchID) | |
print(value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment