Updated for Xcode 14.0 beta 1
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)")
}
}
}
Download this as an Xcode project
SPONSORED In-app subscriptions are a pain. The code can be hard to write, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.