Updated for Xcode 12.5
SwiftUI’s SecureField
works almost identically to a regular TextField
except the characters are masked out for privacy. Just like TextField
, you get to provide a placeholder giving the user a suggestion for what to enter, and the underlying value you bind to is still a plain string so you can check it as needed.
Here’s an example that creates a SecureField
bound to a local @State
property so we can show what they typed:
struct ContentView: View {
@State private var password: String = ""
var body: some View {
VStack {
SecureField("Enter a password", text: $password)
Text("You entered: \(password)")
}
}
}
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.