

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:) |
文字转换 (完整信息) |
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)")
}
}
}
}