william-weng/wwzhconverter
- [Convert the words and phrases between the two sides of the Taiwan Strait and the three places into each other (Use ZHConverter).](https://zhconvert.org/)
[Introduction - 簡介](https://swiftpackageindex.com/William-Weng)
- Convert the words and phrases between the two sides of the Taiwan Strait and the three places into each other (Use ZHConverter).
- 轉換兩岸三地之間的用語 (使用「繁化姬」API)。
[WWZHConverter]
[Installation with Swift Package Manager](https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/使用-spm-安裝第三方套件-xcode-11-新功能-2c4ffcf85b4b)
dependencies: [
.package(url: "https://github.com/William-Weng/WWZHConverter.git", .upToNextMajor(from: "1.1.4"))
]可用函式
|函式|說明| |-|-| |serviceInfo(result:)|取得API的相關資訊| |convertText(_:to:replaces:differents:texts:strategies:textStyles:result:)|文字轉換 (文字部分)| |convert(text:to:replaces:differents:texts:strategies:textStyles:result:)|文字轉換 (完整資訊)|
Example
import UIKit
import WWZHConverter
final class ViewController: UIViewController {
@IBOutlet weak var twLabel: UILabel!
@IBOutlet weak var cnLabel: UILabel!
@IBOutlet weak var hkLabel: UILabel!
@IBAction func convertToChain(_ sender: UIBarButtonItem) {
convert(text: twLabel.text, type: .China) { text in
Task { await MainActor.run { self.cnLabel.text = text }}
}
}
@IBAction func convertToHK(_ sender: UIBarButtonItem) {
convert(text: twLabel.text, type: .Hongkong) { text in
Task { await MainActor.run { self.hkLabel.text = text }}
}
}
}
private extension ViewController {
func convert(text: String?, type: WWZHConverter.ConverterType, message: @escaping (String) -> Void) {
guard let text = text else { return }
WWZHConverter.shared.convertText(text, to: type) { result in
switch result {
case .failure(let error): message("\(error)")
case .success(let text): message("\(text)")
}
}
}
}Package Metadata
Repository: william-weng/wwzhconverter
Default branch: main
README: README.md