Skip to content

Instantly share code, notes, and snippets.

@mattt
Last active August 29, 2015 14:05
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Terrible misuse of Swift literal convertibles to automatically create Hiragana transliteration of string value.
struct もじれつ: Printable {
let description: String
init(string: String) {
var mutableString = NSMutableString(string: string) as CFMutableString
if CFStringTransform(mutableString, nil, kCFStringTransformLatinHiragana, 0) == 1 {
self.description = mutableString as NSString
} else {
self.description = string
}
}
}
extension もじれつ: StringLiteralConvertible {
static func convertFromExtendedGraphemeClusterLiteral(value: String) -> もじれつ {
return self(string: value)
}
static func convertFromStringLiteral(value: String) -> もじれつ {
return self(string: value)
}
}
let s: もじれつ = "hiragana" // ひらがな
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment