Skip to content

Instantly share code, notes, and snippets.

@Winchariot
Created December 18, 2017 16:06
Show Gist options
  • Save Winchariot/753d3cbfadf6a71a995699946b6c0790 to your computer and use it in GitHub Desktop.
Save Winchariot/753d3cbfadf6a71a995699946b6c0790 to your computer and use it in GitHub Desktop.
Validate nonempty string
extension String {
//Validate both that a string is nonempty and that it contains something besides whitespace.
// Useful for driving things like enabling a submit button only when a user has entered (meaningful) text
var isVisuallyEmpty: Bool {
return self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment