Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift 2.0 gist to quickly determine if a String contains an uppercase alphabetical character
extension String {
func containsUpperCaseLetter() -> Bool {
let beginCodePoint = Character("A").unicodeScalarCodePoint()
let endCodePoint = Character("Z").unicodeScalarCodePoint()
for scalar in self.unicodeScalars {
if case beginCodePoint...endCodePoint = scalar.value {
return true
}
}
return false
}
}
extension Character {
func unicodeScalarCodePoint() -> UInt32 {
let characterString = String(self)
let scalars = characterString.unicodeScalars
return scalars[scalars.startIndex].value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment