From e3a339a857feb99a777de22a723501b845aeaaa8 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 11 Nov 2020 16:36:03 -0500 Subject: [PATCH] error check for label --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index efbe3aad..3f485099 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -351,9 +351,13 @@ public typealias ActionBlock = () -> () } else { imageAttachment = Label.getTextAttachmentImage(name: imageName, dimension: fontSize) } - let mutableString = NSMutableAttributedString() - mutableString.append(NSAttributedString(attachment: imageAttachment)) - attributedString.insert(mutableString, at: imageAtt.location) + + // Confirm that the intended image location is within range. + if 0...labelText.count ~= imageAtt.location { + let mutableString = NSMutableAttributedString() + mutableString.append(NSAttributedString(attachment: imageAttachment)) + attributedString.insert(mutableString, at: imageAtt.location) + } case let fontAtt as LabelAttributeFontModel: if let fontStyle = fontAtt.style {