Created
August 10, 2020 04:30
-
-
Save olivaresf/748185715f6e2759f37e89d1ff8bd677 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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