Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 {
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 via
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
You can’t perform that action at this time.