diff --git a/VDS/Components/Label/Attributes/LabelAttributeAction.swift b/VDS/Components/Label/Attributes/LabelAttributeAction.swift index a7a96c3e..584ba947 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeAction.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeAction.swift @@ -19,11 +19,7 @@ public struct LabelAttributeActionModel: LabelAttributeActionable { lhs.isEqual(rhs) } - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: LabelAttributeActionModel) -> Bool { return id == equatable.id && range == equatable.range } diff --git a/VDS/Components/Label/Attributes/LabelAttributeColor.swift b/VDS/Components/Label/Attributes/LabelAttributeColor.swift index 0313cd43..b63781ca 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeColor.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeColor.swift @@ -9,11 +9,7 @@ import Foundation import UIKit public struct LabelAttributeColor: LabelAttributeModel { - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: LabelAttributeColor) -> Bool { return id == equatable.id && range == equatable.range && color == equatable.color } //-------------------------------------------------- diff --git a/VDS/Components/Label/Attributes/LabelAttributeFont.swift b/VDS/Components/Label/Attributes/LabelAttributeFont.swift index 5f0eeefb..15a0da1b 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeFont.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeFont.swift @@ -9,11 +9,7 @@ import Foundation import UIKit public struct LabelAttributeFont: LabelAttributeModel { - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: LabelAttributeFont) -> Bool { return id == equatable.id && range == equatable.range && color == equatable.color diff --git a/VDS/Components/Label/Attributes/LabelAttributeStrikeThrough.swift b/VDS/Components/Label/Attributes/LabelAttributeStrikeThrough.swift index 7c44120e..67341da7 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeStrikeThrough.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeStrikeThrough.swift @@ -9,11 +9,7 @@ import Foundation import UIKit public struct LabelAttributeStrikeThrough: LabelAttributeModel { - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: LabelAttributeStrikeThrough) -> Bool { return id == equatable.id && range == equatable.range } diff --git a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift index c2ce4a1e..2796e4f6 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeUnderline.swift @@ -10,11 +10,7 @@ import UIKit public struct LabelAttributeUnderline: LabelAttributeModel { - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: LabelAttributeUnderline) -> Bool { return id == equatable.id && range == equatable.range && color == equatable.color diff --git a/VDS/Components/Label/LabelModel.swift b/VDS/Components/Label/LabelModel.swift index 04d19e04..51987176 100644 --- a/VDS/Components/Label/LabelModel.swift +++ b/VDS/Components/Label/LabelModel.swift @@ -15,14 +15,10 @@ public protocol LabelModel: Modelable, Labelable { public struct DefaultLabelModel: LabelModel, AnyEquatable, Equatable { public static func == (lhs: DefaultLabelModel, rhs: DefaultLabelModel) -> Bool { - lhs.isEqual(rhs) + lhs.isEqualSelf(rhs) } - public func isEqual(_ equatable: AnyEquatable) -> Bool { - guard let equatable = equatable as? Self else { - return false - } - + public func isEqualSelf(_ equatable: DefaultLabelModel) -> Bool { return id == equatable.id && attributes == equatable.attributes && text == equatable.text diff --git a/VDS/Protocols/AnyEquatable.swift b/VDS/Protocols/AnyEquatable.swift index 2e1708ac..54a96aef 100644 --- a/VDS/Protocols/AnyEquatable.swift +++ b/VDS/Protocols/AnyEquatable.swift @@ -8,10 +8,20 @@ import Foundation public protocol AnyEquatable { - func isEqual(_ equatable: AnyEquatable) -> Bool + func isEqual(_ equatable: any AnyEquatable) -> Bool + func isEqualSelf(_ equatable: Self) -> Bool } -func == (lhs: AnyEquatable?, rhs: AnyEquatable?) -> Bool { +extension AnyEquatable { + public func isEqual(_ equatable: any AnyEquatable) -> Bool { + guard let equatable = equatable as? Self else { + return false + } + return isEqualSelf(equatable) + } +} + +func == (lhs: (any AnyEquatable)?, rhs: (any AnyEquatable)?) -> Bool { switch (lhs, rhs) { case (.some(let lhs), .some(let rhs)): return lhs.isEqual(rhs) @@ -22,11 +32,11 @@ func == (lhs: AnyEquatable?, rhs: AnyEquatable?) -> Bool { } } -func != (lhs: AnyEquatable?, rhs: AnyEquatable?) -> Bool { +func != (lhs: (any AnyEquatable)?, rhs: (any AnyEquatable)?) -> Bool { return !(lhs == rhs) } -func == (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { +func == (lhs: [any AnyEquatable]?, rhs: [any AnyEquatable]?) -> Bool { switch (lhs, rhs) { case (.some(let lhs), .some(let rhs)): return lhs == rhs @@ -37,16 +47,16 @@ func == (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { } } -func != (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { +func != (lhs: [any AnyEquatable]?, rhs: [any AnyEquatable]?) -> Bool { return !(lhs == rhs) } -func == (lhs: [AnyEquatable], rhs: [AnyEquatable]) -> Bool { +func == (lhs: [any AnyEquatable], rhs: [any AnyEquatable]) -> Bool { return lhs.elementsEqual(rhs, by: { (lhsElement, rhsElement) -> Bool in return lhsElement == rhsElement }) } -func != (lhs: [AnyEquatable], rhs: [AnyEquatable]) -> Bool { +func != (lhs: [any AnyEquatable], rhs: [any AnyEquatable]) -> Bool { return !(lhs == rhs) }