Created
March 26, 2017 04:11
-
-
Save lizixroy/301c33d18d9fecfa6c31ee9c6c703d0a to your computer and use it in GitHub Desktop.
blog
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
func submitButtonPressed { | |
showLoadingWheel() | |
defer { hideLoadingWheel() } | |
guard let username = validateInput() else { | |
showErrorAlert() | |
return | |
} | |
let payload = ["username": username]; | |
webService.sendPOSTRequest(withPayload: payload) | |
} | |
func validateInput -> String? { | |
guard let username = self.usernameField.text else { return nil } | |
let trimmedUsername = username.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) | |
return trimmedUsername.length > 0 ? trimmedUsername : nil | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment