TISExtension // Enhancing type safety.
This commit is contained in:
parent
2e58eca255
commit
a5eacbcadc
|
@ -85,7 +85,7 @@ extension TISInputSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var inputModeID: String {
|
public var inputModeID: String {
|
||||||
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyInputModeID), to: NSString.self) as String
|
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyInputModeID), to: NSString.self) as String? ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
public var vChewingLocalizedName: String {
|
public var vChewingLocalizedName: String {
|
||||||
|
@ -106,18 +106,18 @@ extension TISInputSource {
|
||||||
|
|
||||||
extension TISInputSource {
|
extension TISInputSource {
|
||||||
public var localizedName: String {
|
public var localizedName: String {
|
||||||
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyLocalizedName), to: NSString.self) as String
|
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyLocalizedName), to: NSString.self) as String? ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
public var identifier: String {
|
public var identifier: String {
|
||||||
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyInputSourceID), to: NSString.self) as String
|
unsafeBitCast(TISGetInputSourceProperty(self, kTISPropertyInputSourceID), to: NSString.self) as String? ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
public var scriptCode: Int {
|
public var scriptCode: Int {
|
||||||
// Shiki's note: There is no "kTISPropertyScriptCode" in TextInputSources.h file.
|
// Shiki's note: There is no "kTISPropertyScriptCode" in TextInputSources.h file.
|
||||||
// Using Mzp's latest solution in his blog: https://mzp.hatenablog.com/entry/2018/07/16/212026
|
// Using Mzp's latest solution in his blog: https://mzp.hatenablog.com/entry/2018/07/16/212026
|
||||||
let r = TISGetInputSourceProperty(self, "TSMInputSourcePropertyScriptCode" as CFString)
|
let r = TISGetInputSourceProperty(self, "TSMInputSourcePropertyScriptCode" as CFString)
|
||||||
return unsafeBitCast(r, to: NSString.self).integerValue
|
return unsafeBitCast(r, to: NSString.self).integerValue as Int? ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func rawTISInputSources(onlyASCII: Bool = false) -> [String: TISInputSource] {
|
public static func rawTISInputSources(onlyASCII: Bool = false) -> [String: TISInputSource] {
|
||||||
|
|
Loading…
Reference in New Issue