Try to search your question here, if you can't find : Ask Any Question Now ?

Swift – password protected view controller

HomeCategory: stackoverflowSwift – password protected view controller
Avatarwillson asked 4 months ago

Another swift beginner here.

Essentially tying to make a password protected view controller.

so far –

Created storyboard –
on viewcontroller – created hard coded log in –
prints to console if successful or not.

textfields etc…

@IBOutlet weak var untext: UITextField!

@IBOutlet weak var pwtext: UITextField!

let username = "admin"
let password = "adminpw"

override func viewDidLoad() {
    pwtext.isSecureTextEntry = true

@IBAction func loginbtn(_ sender: Any) {
    if untext.text == username && pwtext.text == password
        print("log in succesful")
    }   else {
        print("log in failed")


The issue i have, once i press the login button, it takes me to the admin page if successful or not.

how can i print a notification – on screen – if unsucessful and remain on the current view controller, and if successful, take me to admin view controller?


1 Answers
Best Answer
AvatarFernando answered 4 months ago
Your Answer

18 + 20 =

Popular Tags

WP Facebook Auto Publish Powered By :