WWJavaScriptContext+Pinyin

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

Introduction - 简介

Installation with Swift Package Manager - 使用 Swift Package Manager 安装

dependencies: [
    .package(url: "https://github.com/William-Weng/WWJavaScriptContext_Pinyin.git", .upToNextMajor(from: "1.0.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
    }
}