diff --git a/Example/RSNumberPad/AppDelegate.swift b/Example/RSNumberPad/AppDelegate.swift index 09b07de..29d976c 100644 --- a/Example/RSNumberPad/AppDelegate.swift +++ b/Example/RSNumberPad/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Example/RSNumberPad/ViewController.swift b/Example/RSNumberPad/ViewController.swift index 53892d0..ee121a7 100644 --- a/Example/RSNumberPad/ViewController.swift +++ b/Example/RSNumberPad/ViewController.swift @@ -10,7 +10,7 @@ import UIKit import RSNumberPad class ViewController: UIViewController { - + @IBOutlet private weak var numberPadTextField: RSNumberPad! override func viewDidLoad() { @@ -18,25 +18,29 @@ class ViewController: UIViewController { } @IBAction private func saveButtonDidTap(_ sender: Any) { - guard let password = numberPadTextField.text else { - print("No password entered.") + guard let password = numberPadTextField.text, !password.isEmpty else { + showAlert(withTitle: "Error", message: "No password entered.") return } numberPadTextField.savePassword(key: "password", password: password) - print("Password has been saved.") + showAlert(withTitle: "Success", message: "Password has been saved.") } @IBAction private func checkButtonDidTap(_ sender: Any) { - - guard let password = numberPadTextField.text else { - print("No password entered.") + guard let password = numberPadTextField.text, !password.isEmpty else { + showAlert(withTitle: "Error", message: "No password entered.") return } if numberPadTextField.checkPassword(key: "password", password: password) { - print("Input matches the saved password.") + showAlert(withTitle: "Success", message: "Input matches the saved password.") } else { - print("Input doesn't match the saved password.") + showAlert(withTitle: "Error", message: "Input doesn't match the saved password.") } } + + private func showAlert(withTitle title: String, message: String) { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } } -