Skip to content

Instantly share code, notes, and snippets.

@barrault01
Created March 29, 2022 07:33
Show Gist options
  • Save barrault01/4572744542b6def50192c4593d899a75 to your computer and use it in GitHub Desktop.
Save barrault01/4572744542b6def50192c4593d899a75 to your computer and use it in GitHub Desktop.
A simple signup view to demonstrating the benefits of CombineLatest
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