Created
July 2, 2016 20:09
-
-
Save littlebobert/b592f2e2b74c03e7f2250c0979f6a811 to your computer and use it in GitHub Desktop.
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
import Foundation | |
extension String { | |
func containsOnlyWhitespace() -> Bool { | |
let pattern = "^[\\s]+$" | |
let regex = try! NSRegularExpression(pattern: pattern, options: .DotMatchesLineSeparators) | |
let matches = regex.matchesInString(self, options: .ReportCompletion, range: NSMakeRange(0, self.characters.count)) | |
return matches.count > 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!