vds_ios/VDS/Components/Label/Attributes/AnyLabelAttribute.swift
Matt Bruce 05638422f6 updated labels to ensure string is valid
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-02-28 13:04:11 -06:00

38 lines
1.1 KiB
Swift

//
// 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)
}
}