WWJavaScriptContext+Pinyin

main

Convert Chinese characters to Hanyu Pinyin.
William-Weng/WWJavaScriptContext_Pinyin

WWJavaScriptContext+Pinyin

Swift-5.6 iOS-14.0 Swift Package Manager-SUCCESS LICENSE

dependencies: [
    .package(url: "https://github.com/William-Weng/WWJavaScriptContext_Pinyin.git", .upToNextMajor(from: "1.0.0"))
]

Function - 可用函式

函式 功能
convertText(_:outputType:toneType:) 中文字 => 漢語拼音

Example

import UIKit
import WWPrint
import WWJavaScriptContext
import WWJavaScriptContext_Pinyin

final class ViewController: UIViewController {

    private let text = "漢語拼音測試" // hàn yǔ pīn yīn cè shì
    
    override func viewDidLoad() {
        super.viewDidLoad()
        pinyinTest(source: text)
    }
}

// MARK: - 小工具
private extension ViewController {
    
    /// 拼音測試
    /// - Parameter source: String
    func pinyinTest(source: String) {
        
        guard let value = WWJavaScriptContext.Pinyin.shared.convertText(text, outputType: .text, toneType: .general),
              let pinyinText = value.toString()
        else {
            return
        }
        
        wwPrint("\(text) => \(pinyinText)")
    }
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Sun Oct 20 2024 05:48:38 GMT-0900 (Hawaii-Aleutian Daylight Time)