How can you use the \"ctype.h\" library in Swift to be able to use isAlpha
or isSpace
on characters? Or is there a better, Swift, way of doing it?
I created a String extension that does exactly this, hope it's useful.
extension String {
func containsWhitespaceAndNewlines() -> Bool {
return rangeOfCharacter(from: .whitespacesAndNewlines) != nil
}
}
// Usage
"hello, world!".containsWhitespaceAndNewlines() // true
"hello,world!".containsWhitespaceAndNewlines() // false