Skip to content

Commit

Permalink
chore: edit sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
devxsby committed Jul 1, 2023
1 parent 98237e6 commit 46a097f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Example/RSNumberPad/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 14 additions & 10 deletions Example/RSNumberPad/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,37 @@ import UIKit
import RSNumberPad

class ViewController: UIViewController {

@IBOutlet private weak var numberPadTextField: RSNumberPad!

override func viewDidLoad() {
super.viewDidLoad()
}

@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)
}
}

0 comments on commit 46a097f

Please sign in to comment.