You can do this by using properties of textfield from Attribute inspector
Tap on Your Textfield from storyboard and go to Attribute inspector , and just check the checkbox of "Secure Text Entry" SS is added for graphical overview to achieve same
In XCode 6.3.1, if you use a NSTextField
you will not see the checkbox for secure
.
Instead of using NSTextField
use NSSecureTextField
I'm guessing this is a Swift/Objective-C change since there is now a class for secure text fields. In the above link it says Available in OS X v10.0 and later.
If you know more about when/why/what versions of Swift/Objective-C, XCode, or OS X this
in Swift 3.0 or Later
passwordTextField.isSecureTextEntry = true
Programmatically (Swift 4 & 5)
self.passwordTextField.isSecureTextEntry = true
For SwiftUI, try
TextField ("Email", text: $email)
.textFieldStyle(RoundedBorderTextFieldStyle()).padding()
SecureField ("Password", text: $password)
.textFieldStyle(RoundedBorderTextFieldStyle()).padding()
Source: Stackoverflow.com