Skip to content

Instantly share code, notes, and snippets.

@kocyigityunus
Created August 19, 2019 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kocyigityunus/4bd0cdf6918a89d082edeb86c53c8644 to your computer and use it in GitHub Desktop.
Save kocyigityunus/4bd0cdf6918a89d082edeb86c53c8644 to your computer and use it in GitHub Desktop.
CharacterSet+getCharacters()
extension CharacterSet {
func getCharacters() -> [String] {
let characterSet = self as NSCharacterSet
var characters: [String] = []
for plane:UInt8 in 0..<17 {
if characterSet.hasMemberInPlane(plane) {
let planeStart = UInt32(plane) << 16
let nextPlaneStart = (UInt32(plane) + 1) << 16
for char: UTF32Char in planeStart..<nextPlaneStart {
if characterSet.longCharacterIsMember(char) {
if let unicodeCharacter = UnicodeScalar(char) {
characters.append(String(unicodeCharacter))
}
}
}
}
}
return characters
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment