updated to equalSelf

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-09-15 16:50:21 -05:00
parent b4659a73c0
commit 378802eb5e
7 changed files with 24 additions and 38 deletions

View File

@ -19,11 +19,7 @@ public struct LabelAttributeActionModel: LabelAttributeActionable {
lhs.isEqual(rhs) lhs.isEqual(rhs)
} }
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: LabelAttributeActionModel) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id && range == equatable.range return id == equatable.id && range == equatable.range
} }

View File

@ -9,11 +9,7 @@ import Foundation
import UIKit import UIKit
public struct LabelAttributeColor: LabelAttributeModel { public struct LabelAttributeColor: LabelAttributeModel {
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: LabelAttributeColor) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id && range == equatable.range && color == equatable.color return id == equatable.id && range == equatable.range && color == equatable.color
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -9,11 +9,7 @@ import Foundation
import UIKit import UIKit
public struct LabelAttributeFont: LabelAttributeModel { public struct LabelAttributeFont: LabelAttributeModel {
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: LabelAttributeFont) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range
&& color == equatable.color && color == equatable.color

View File

@ -9,11 +9,7 @@ import Foundation
import UIKit import UIKit
public struct LabelAttributeStrikeThrough: LabelAttributeModel { public struct LabelAttributeStrikeThrough: LabelAttributeModel {
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: LabelAttributeStrikeThrough) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range
} }

View File

@ -10,11 +10,7 @@ import UIKit
public struct LabelAttributeUnderline: LabelAttributeModel { public struct LabelAttributeUnderline: LabelAttributeModel {
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: LabelAttributeUnderline) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range
&& color == equatable.color && color == equatable.color

View File

@ -15,14 +15,10 @@ public protocol LabelModel: Modelable, Labelable {
public struct DefaultLabelModel: LabelModel, AnyEquatable, Equatable { public struct DefaultLabelModel: LabelModel, AnyEquatable, Equatable {
public static func == (lhs: DefaultLabelModel, rhs: DefaultLabelModel) -> Bool { public static func == (lhs: DefaultLabelModel, rhs: DefaultLabelModel) -> Bool {
lhs.isEqual(rhs) lhs.isEqualSelf(rhs)
} }
public func isEqual(_ equatable: AnyEquatable) -> Bool { public func isEqualSelf(_ equatable: DefaultLabelModel) -> Bool {
guard let equatable = equatable as? Self else {
return false
}
return id == equatable.id return id == equatable.id
&& attributes == equatable.attributes && attributes == equatable.attributes
&& text == equatable.text && text == equatable.text

View File

@ -8,10 +8,20 @@
import Foundation import Foundation
public protocol AnyEquatable { 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) { switch (lhs, rhs) {
case (.some(let lhs), .some(let rhs)): case (.some(let lhs), .some(let rhs)):
return lhs.isEqual(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) return !(lhs == rhs)
} }
func == (lhs: [AnyEquatable]?, rhs: [AnyEquatable]?) -> Bool { func == (lhs: [any AnyEquatable]?, rhs: [any AnyEquatable]?) -> Bool {
switch (lhs, rhs) { switch (lhs, rhs) {
case (.some(let lhs), .some(let rhs)): case (.some(let lhs), .some(let rhs)):
return lhs == 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) 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 lhs.elementsEqual(rhs, by: { (lhsElement, rhsElement) -> Bool in
return lhsElement == rhsElement return lhsElement == rhsElement
}) })
} }
func != (lhs: [AnyEquatable], rhs: [AnyEquatable]) -> Bool { func != (lhs: [any AnyEquatable], rhs: [any AnyEquatable]) -> Bool {
return !(lhs == rhs) return !(lhs == rhs)
} }