A lightweight Swift library supporting convertion between Chinese(both Simplified and Tranditional) characters and Pinyin.
Specify "HanziPinyin" in your Cartfile
:
github "teambition/HanziPinyin"
Specify "HanziPinyin" in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'HanziPinyin'
// PinyinToneType: none, toneNumber
// PinyinVCharType: vCharacter, uUnicode, uAndColon
// PinyinCaseType: lowercased, uppercased, capitalized
let outputFormat = PinyinOutputFormat(toneType: .none, vCharType: .vCharacter, caseType: .lowercased)
print("我爱中文".toPinyin(withFormat: outputFormat, separator: " "))
// wo ai zhong wen
print("我愛說中國話".toPinyin(withFormat: outputFormat, separator: " "))
// wo ai shuo zhong guo hua
print("我爱中文".toPinyinAcronym())
// wazw
print("I love Chinese.".toPinyin())
// I love Chinese.
"我爱中文".toPinyin { (pinyin) in
// do something
}
"我爱中文".toPinyinAcronym { (pinyin) in
// do something
}
print("我爱中文".hasChineseCharacter)
// true
print("I love Chinese.".hasChineseCharacter)
// false
iOS 8.0
HanziPinyin is released under the MIT license. See LICENSE for details.
Have a question? Please open an issue!