Skip to content

Commit

Permalink
Make OpenCCBridge.shared a public static var
Browse files Browse the repository at this point in the history
This avoids a swiftc issue when compiling with `-O`.
  • Loading branch information
lukhnos committed Oct 3, 2023
1 parent ed8f301 commit 7918e0e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import OpenCC
/// Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass
/// in Swift in order to bridge the Swift classes into our Objective-C++ project.
public class OpenCCBridge: NSObject {
private static let shared = OpenCCBridge()

@objc(sharedInstance) public static let shared = OpenCCBridge()

private var converter: ChineseConverter?

private override init() {
Expand All @@ -38,10 +40,10 @@ public class OpenCCBridge: NSObject {
}

/// Converts to Simplified Chinese.
///
///
/// - Parameter string: Text in Traditional Chinese.
/// - Returns: Text in Simplified Chinese.
@objc public static func convertToSimplified(_ string: String) -> String? {
shared.converter?.convert(string)
@objc public func convertToSimplified(_ string: String) -> String? {
converter?.convert(string)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import XCTest
final class OpenCCBridgeTests: XCTestCase {
func testTC2SC() throws {
let text = "繁體中文轉簡體中文"
let converted = OpenCCBridge.convertToSimplified(text)
let converted = OpenCCBridge.shared.convertToSimplified(text)
XCTAssert(converted == "繁体中文转简体中文")
}
}
2 changes: 1 addition & 1 deletion Source/InputMethodController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ extension McBopomofoInputMethodController {
if Preferences.chineseConversionStyle == 1 {
return text
}
return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.convertToSimplified(text) ?? ""
return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.shared.convertToSimplified(text) ?? ""
}

let buffer = convertToSimplifiedChineseIfRequired(text)
Expand Down
2 changes: 1 addition & 1 deletion Source/LanguageModelManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ + (void)setupDataModelValueConverter
if (Preferences.chineseConversionEngine == 1) {
text = [VXHanConvert convertToSimplifiedFrom:text];
} else {
text = [OpenCCBridge convertToSimplified:text];
text = [[OpenCCBridge sharedInstance] convertToSimplified:text];
}
return std::string(text.UTF8String);
};
Expand Down

0 comments on commit 7918e0e

Please sign in to comment.