Created
August 12, 2015 03:04
-
-
Save jasdev/470028004114af75c748 to your computer and use it in GitHub Desktop.
Swift 2.0 gist to quickly determine if a String contains an uppercase alphabetical character
This file contains 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
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