Skip to content

Instantly share code, notes, and snippets.

@littlebobert
Created July 2, 2016 20:09
Show Gist options
  • Save littlebobert/b592f2e2b74c03e7f2250c0979f6a811 to your computer and use it in GitHub Desktop.
Save littlebobert/b592f2e2b74c03e7f2250c0979f6a811 to your computer and use it in GitHub Desktop.
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
}
}
@jamiecropley
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment