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?
Shorter extension (swift 4.1)
extension String {
var containsWhitespace : Bool {
return(self.rangeOfCharacter(from: .whitespacesAndNewlines) != nil)
}
}
You can change the .whitespacesAndNewlines
with any other CharacterSet
like this:
extension String {
var containsDigits : Bool {
return(self.rangeOfCharacter(from: CharacterSet.decimalDigits) != nil)
}
}