@@ -496,6 +496,7 @@ open class Attributer {
496
496
*/
497
497
open func fontName( _ fontName: String ) -> Attributer {
498
498
for range in self . ranges {
499
+ guard range. location != NSNotFound else { return self }
499
500
let substring = self . attributedText. attributedSubstring ( from: range)
500
501
if substring. length > 0 , let font = substring. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont {
501
502
if let currentFont = UIFont ( name: fontName, size: font. pointSize) {
@@ -517,6 +518,7 @@ open class Attributer {
517
518
*/
518
519
open func size( _ size: CGFloat ) -> Attributer {
519
520
for range in self . ranges {
521
+ guard range. location != NSNotFound else { return self }
520
522
let substring = self . attributedText. attributedSubstring ( from: range)
521
523
if substring. length > 0 , let font = substring. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont {
522
524
self . attributedText. addAttribute ( NSAttributedString . Key. font, value: UIFont ( name: font. fontName, size: size) !, range: range)
@@ -550,6 +552,7 @@ open class Attributer {
550
552
@available ( * , deprecated, message: " use AttributedTextView with makeInteract: instead " )
551
553
open func makeInteractWithURLforScheme( _ scheme: String ) -> Attributer {
552
554
for nsRange in self . ranges {
555
+ guard nsRange. location != NSNotFound else { return self }
553
556
let iRange = self . attributedText. string. range ( from: nsRange)
554
557
if let escapedString = self . attributedText. string. substring ( with: iRange!) . addingPercentEncoding ( withAllowedCharacters: NSCharacterSet . urlHostAllowed) {
555
558
self . attributedText. addAttribute ( NSAttributedString . Key. link, value: " \( scheme) : \( escapedString) " , range: nsRange)
@@ -565,6 +568,7 @@ open class Attributer {
565
568
*/
566
569
open func makeInteract( _ callback: @escaping ( ( _ link: String ) -> ( ) ) ) -> Attributer {
567
570
for nsRange in self . ranges {
571
+ guard nsRange. location != NSNotFound else { return self }
568
572
let unEscapedString = ( self . attributedText. string as NSString ) . substring ( with: nsRange)
569
573
let escapedString = unEscapedString. addingPercentEncoding ( withAllowedCharacters: NSCharacterSet . urlHostAllowed) ?? " "
570
574
self . attributedText. addAttribute ( NSAttributedString . Key. link, value: " AttributedTextView: \( escapedString) " , range: nsRange)
@@ -1111,6 +1115,7 @@ open class Attributer {
1111
1115
@discardableResult
1112
1116
fileprivate func applyAttributes( _ attributeName: String , value: AnyObject ) -> Attributer {
1113
1117
for range in self . ranges {
1118
+ guard range. location != NSNotFound else { return self }
1114
1119
self . attributedText. addAttribute ( NSAttributedString . Key ( rawValue: attributeName) , value: value, range: range)
1115
1120
}
1116
1121
return self
0 commit comments