@@ -496,6 +496,7 @@ open class Attributer {
496496 */
497497 open func fontName( _ fontName: String ) -> Attributer {
498498 for range in self . ranges {
499+ guard range. location != NSNotFound else { return self }
499500 let substring = self . attributedText. attributedSubstring ( from: range)
500501 if substring. length > 0 , let font = substring. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont {
501502 if let currentFont = UIFont ( name: fontName, size: font. pointSize) {
@@ -517,6 +518,7 @@ open class Attributer {
517518 */
518519 open func size( _ size: CGFloat ) -> Attributer {
519520 for range in self . ranges {
521+ guard range. location != NSNotFound else { return self }
520522 let substring = self . attributedText. attributedSubstring ( from: range)
521523 if substring. length > 0 , let font = substring. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont {
522524 self . attributedText. addAttribute ( NSAttributedString . Key. font, value: UIFont ( name: font. fontName, size: size) !, range: range)
@@ -550,6 +552,7 @@ open class Attributer {
550552 @available ( * , deprecated, message: " use AttributedTextView with makeInteract: instead " )
551553 open func makeInteractWithURLforScheme( _ scheme: String ) -> Attributer {
552554 for nsRange in self . ranges {
555+ guard nsRange. location != NSNotFound else { return self }
553556 let iRange = self . attributedText. string. range ( from: nsRange)
554557 if let escapedString = self . attributedText. string. substring ( with: iRange!) . addingPercentEncoding ( withAllowedCharacters: NSCharacterSet . urlHostAllowed) {
555558 self . attributedText. addAttribute ( NSAttributedString . Key. link, value: " \( scheme) : \( escapedString) " , range: nsRange)
@@ -1112,6 +1115,7 @@ open class Attributer {
11121115 @discardableResult
11131116 fileprivate func applyAttributes( _ attributeName: String , value: AnyObject ) -> Attributer {
11141117 for range in self . ranges {
1118+ guard range. location != NSNotFound else { return self }
11151119 self . attributedText. addAttribute ( NSAttributedString . Key ( rawValue: attributeName) , value: value, range: range)
11161120 }
11171121 return self
0 commit comments