vds_ios/VDS/Components/Label/Attributes/AttachmentLabelAttributeModel.swift
Matt Bruce 1d9667c173 added validators for invalid range
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-03-20 15:24:59 -05:00

29 lines
768 B
Swift

//
// LabelAttributeAttachment.swift
// VDS
//
// Created by Matt Bruce on 8/9/22.
//
import Foundation
import UIKit
public protocol AttachmentLabelAttributeModel: LabelAttributeModel {
func getAttachment() throws -> NSTextAttachment
}
extension AttachmentLabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) {
guard isValidRange(on: attributedString) else { return }
do {
let mutableString = NSMutableAttributedString()
let attachment = try getAttachment()
mutableString.append(NSAttributedString(attachment: attachment))
attributedString.insert(mutableString, at: location)
} catch {
//TODO: Error Handling
}
}
}