NEW: Get your ticket for Hacking with Swift Live 2019! >>

< How to add a border to a TextField   How to create a Slider and read values from it >

How to create secure text fields using SecureField

SwiftUI’s SecureField works almost identically to a regular TextField except the characters are masked out for privacy. The underlying value you bind it to is still a plain string, of course, 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($password)
            Text("You entered: \(password)")
        }
    }
}

HACKING WITH SWIFT LIVE This July is a new two-day event where you'll be inspired by great speakers on day one then learn all the amazing new features from WWDC on day two – click here for more information and tickets.

< How to add a border to a TextField   How to create a Slider and read values from it >
MASTER SWIFT NOW
Buy Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let me know!

Average rating: 4.7/5

Click here to visit the Hacking with Swift store >>