Updated for Xcode 14.2
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 From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.