// // AnyAttribute.swift // VDS // // Created by Matt Bruce on 11/10/22. // import Foundation public struct AnyAttribute: LabelAttributeModel { public var id = UUID() public var location: Int public var length: Int public var key: NSAttributedString.Key public var value: AnyHashable public init(location: Int, length: Int, key: NSAttributedString.Key, value: AnyHashable) { self.location = location self.length = length self.key = key self.value = value } public func isEqual(_ equatable: AnyAttribute) -> Bool { return id == equatable.id && range == equatable.range && key == equatable.key && value == equatable.value } public static func == (lhs: AnyAttribute, rhs: AnyAttribute) -> Bool { lhs.isEqual(rhs) } public func setAttribute(on attributedString: NSMutableAttributedString) { guard isValidRange(on: attributedString) else { return } attributedString.removeAttribute(key, range: range) attributedString.addAttribute(key, value: value, range: range) } }