Created
May 30, 2015 07:21
-
-
Save StanislavK/613d272c4b68485ddc58 to your computer and use it in GitHub Desktop.
This file contains 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
//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