Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save olivaresf/748185715f6e2759f37e89d1ff8bd677 to your computer and use it in GitHub Desktop.
Save olivaresf/748185715f6e2759f37e89d1ff8bd677 to your computer and use it in GitHub Desktop.
import UIKit
protocol SettingViewControllerProtocol {
var isPasswordProtected: Bool { get set }
func validate(password: String?, confirmPassword: String?, from: SettingViewController) -> Bool
}
class SettingViewController: UIViewController {
var delegate: SettingViewControllerProtocol!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var confirmPasswordTextField: UITextField!
@IBOutlet weak var isPasswordProtected: UISwitch! {
didSet {
isPasswordProtected.isOn = delegate.isPasswordProtected
}
}
}
extension SettingViewController {
@IBAction func passwordProtect(_ sender: UIButton) {
let validPassword = delegate.validate(password: passwordTextField.text,
confirmPassword: confirmPasswordTextField.text,
from: self)
guard validPassword else { return }
delegate.isPasswordProtected = true
}
@IBAction func togglePasswordProtection(_ sender: UISwitch) {
delegate.isPasswordProtected = !isPasswordProtected.isOn
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment