Contents

william-weng/wwjavascriptcontext_pinyin

- [Convert Chinese characters to Hanyu Pinyin.](https://unpkg.com/browse/pinyin-pro@3.19.3/dist/index.js)

[Introduction - 簡介](https://swiftpackageindex.com/William-Weng)

Installation with Swift Package Manager

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

Function - 可用函式

|函式|功能| |-|-| |convert(text:outputType:toneType:)|中文字 => 漢語拼音|

Example

import UIKit
import WWJavaScriptContext
import WWJavaScriptContext_Pinyin

final class ViewController: UIViewController {

    @IBOutlet weak var textLabel: UILabel!
    @IBOutlet weak var pinyinLabel: UILabel!
        
    override func viewDidLoad() {
        super.viewDidLoad()
        pinyinTest(text: textLabel.text)
    }
}

// MARK: - 小工具
private extension ViewController {
    
    func pinyinTest(text: String?) {
        
        guard let text = text,
              let value = WWJavaScriptContext.Pinyin.shared.convert(text: text, outputType: .text, toneType: .general),
              let pinyinText = value.toString()
        else {
            return
        }
        
        pinyinLabel.text = pinyinText
    }
}

Package Metadata

Repository: william-weng/wwjavascriptcontext_pinyin

Default branch: main

README: README.md