Skip to content

Instantly share code, notes, and snippets.

@StanislavK
Created May 30, 2015 07:21
Show Gist options
  • Save StanislavK/613d272c4b68485ddc58 to your computer and use it in GitHub Desktop.
Save StanislavK/613d272c4b68485ddc58 to your computer and use it in GitHub Desktop.
//String extension that checks for an empty (after trimming whitespace) or nil string:
//
// Usage: var isEmpty = String.isNilOrEmpty(myString)
//
// Credit to: Kevin McNeish
// http://iosappsfornonprogrammers.com/forum/index.php?topic=1836.0
extension String {
public static func isNilOrEmpty(string: String?) -> Bool {
switch string?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) {
case .Some(let nonNilString):
return nonNilString.isEmpty
default:
return true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment