Skip to content

Instantly share code, notes, and snippets.

@ZevEisenberg
Last active October 31, 2015 02:33
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 ZevEisenberg/3c00a03177f57d3fee60 to your computer and use it in GitHub Desktop.
Save ZevEisenberg/3c00a03177f57d3fee60 to your computer and use it in GitHub Desktop.
A script that prints all the Unicode characters. I would have uploaded the output as well, but it’s 50 MB and GitHub can’t handle my scale.
import Foundation
func describeCharsInRange(range: Range<Int>) -> String {
return range.map {
let swiftCharacter = Character(UnicodeScalar($0))
let string = String(swiftCharacter)
let hexString = NSString(format: "0x%.6X", $0) as String
// Optional in theory, but in this case it always returns a value
let name = string.stringByApplyingTransform(NSStringTransformToUnicodeName, reverse: false)!
return "\(hexString) - [\(string)] - \(name)\n"
}.reduce("") { $0 + $1 }
}
// ranges from http://www.unicode.org/glossary/#unicode_scalar_value via http://stackoverflow.com/a/32157540/255489
let charString = describeCharsInRange(0x0...0xD7FF) + describeCharsInRange(0xE000...0x10FFFF)
let desktopPath = NSSearchPathForDirectoriesInDomains(.DesktopDirectory, .UserDomainMask, true)[0]
let filePath = (desktopPath as NSString).stringByAppendingPathComponent("allCharacters.txt")
do {
try! charString.writeToFile(filePath, atomically: true, encoding: NSUTF8StringEncoding)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment