File tree Expand file tree Collapse file tree
Examples/Example-iOS/Example-iOS Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,14 +36,28 @@ class InputViewController: UITableViewController {
3636 }
3737
3838 @IBAction func saveAction( sender: UIBarButtonItem ) {
39- let keychain = Keychain ( service: serviceField. text)
40- keychain [ usernameField. text] = passwordField. text
39+ let keychain : Keychain
40+ if let service = serviceField. text where !service. isEmpty {
41+ keychain = Keychain ( service: service)
42+ } else {
43+ keychain = Keychain ( )
44+ }
45+ keychain [ usernameField. text!] = passwordField. text
4146
4247 dismissViewControllerAnimated ( true , completion: nil )
4348 }
4449
4550 @IBAction func editingChanged( sender: UITextField ) {
46- saveButton. enabled = !usernameField. text. isEmpty && !passwordField. text. isEmpty
51+ switch ( usernameField. text, passwordField. text) {
52+ case let ( username? , password? ) :
53+ saveButton. enabled = !username. isEmpty && !password. isEmpty
54+ case ( _? , nil ) :
55+ saveButton. enabled = false
56+ case ( nil , _? ) :
57+ saveButton. enabled = false
58+ case ( nil , nil ) :
59+ saveButton. enabled = false
60+ }
4761 }
4862
4963}
You can’t perform that action at this time.
0 commit comments