vds_ios/VDS/Components/Label/Attributes/AnyLabelAttribute.swift
Matt Bruce cd94bfde67 added AnylabelAttribute
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-11-10 11:25:32 -06:00

37 lines
1.0 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) {
attributedString.removeAttribute(key, range: range)
attributedString.addAttribute(key, value: value, range: range)
}
}