Last active
August 29, 2015 14:05
-
-
Save mattt/1f6c9ab2b4e62cd82a67 to your computer and use it in GitHub Desktop.
Terrible misuse of Swift literal convertibles to automatically create Hiragana transliteration of string value.
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
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