mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-28 18:47:41 +00:00
refactor(ios/engine): resource FullIDs now equatable at protocol level
This commit is contained in:
parent
047b7a2be7
commit
6bdd32628c
3 changed files with 10 additions and 17 deletions
|
|
@ -9,7 +9,7 @@
|
|||
import Foundation
|
||||
|
||||
/// A complete identifier for an `InstallableKeyboard`. Keyboards must have unique `FullKeyboardID`s.
|
||||
public struct FullKeyboardID: Codable, LanguageResourceFullID {
|
||||
public struct FullKeyboardID: Codable, LanguageResourceFullID, Equatable {
|
||||
public var keyboardID: String
|
||||
public var languageID: String
|
||||
|
||||
|
|
@ -22,13 +22,6 @@ public struct FullKeyboardID: Codable, LanguageResourceFullID {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Equatable
|
||||
extension FullKeyboardID: Equatable {
|
||||
public static func ==(lhs: FullKeyboardID, rhs: FullKeyboardID) -> Bool {
|
||||
return lhs.keyboardID == rhs.keyboardID && lhs.languageID == rhs.languageID
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CustomStringConvertible
|
||||
extension FullKeyboardID: CustomStringConvertible {
|
||||
public var description: String {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
import Foundation
|
||||
|
||||
/// A complete identifier for an `InstallableLexicalModel`. LexicalModels must have unique `FullLexicalModelID`s.
|
||||
public struct FullLexicalModelID: Codable, LanguageResourceFullID {
|
||||
public struct FullLexicalModelID: Codable, LanguageResourceFullID, Equatable {
|
||||
public var lexicalModelID: String
|
||||
public var languageID: String
|
||||
|
||||
|
|
@ -22,13 +22,6 @@ public struct FullLexicalModelID: Codable, LanguageResourceFullID {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Equatable
|
||||
extension FullLexicalModelID: Equatable {
|
||||
public static func ==(lhs: FullLexicalModelID, rhs: FullLexicalModelID) -> Bool {
|
||||
return lhs.lexicalModelID == rhs.lexicalModelID && lhs.languageID == rhs.languageID
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CustomStringConvertible
|
||||
extension FullLexicalModelID: CustomStringConvertible {
|
||||
public var description: String {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,19 @@ public enum LanguageResourceType {
|
|||
case keyboard, lexicalModel
|
||||
}
|
||||
|
||||
// Subclasses must implement Equatable; Swift doesn't like it directly on the root protocol.
|
||||
public protocol LanguageResourceFullID {
|
||||
var id: String { get }
|
||||
var languageID: String { get }
|
||||
var type: LanguageResourceType { get }
|
||||
}
|
||||
|
||||
extension LanguageResourceFullID where Self: Equatable {
|
||||
public static func ==(lhs: Self, rhs: Self) -> Bool {
|
||||
return lhs.id == rhs.id && lhs.languageID == rhs.languageID && lhs.type == rhs.type
|
||||
}
|
||||
}
|
||||
|
||||
// Alas, 'associatedtype' stuff isn't exactly generic, and it's impossible to wildcard.
|
||||
// So, this supports Swift's "type erasure" pattern, acting as a "wildcarded"
|
||||
// LanguageResource that doesn't care about the specific associatedtype(s) that
|
||||
|
|
@ -41,7 +48,7 @@ public protocol AnyLanguageResource {
|
|||
// Necessary due to Swift details 'documented' at
|
||||
// https://stackoverflow.com/questions/42561685/why-cant-a-get-only-property-requirement-in-a-protocol-be-satisfied-by-a-proper
|
||||
public protocol LanguageResource: AnyLanguageResource {
|
||||
associatedtype FullID: LanguageResourceFullID
|
||||
associatedtype FullID: LanguageResourceFullID where FullID: Equatable
|
||||
var typedFullID: FullID { get }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue