Skip to content

Commit a949085

Browse files
committed
2 parents c7f200c + 1545b19 commit a949085

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sources/Attributer.swift

+5
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -565,6 +568,7 @@ open class Attributer {
565568
*/
566569
open func makeInteract(_ callback: @escaping ((_ link: String) -> ())) -> Attributer {
567570
for nsRange in self.ranges {
571+
guard nsRange.location != NSNotFound else { return self }
568572
let unEscapedString = (self.attributedText.string as NSString).substring(with: nsRange)
569573
let escapedString = unEscapedString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlHostAllowed) ?? ""
570574
self.attributedText.addAttribute(NSAttributedString.Key.link, value: "AttributedTextView:\(escapedString)", range: nsRange)
@@ -1111,6 +1115,7 @@ open class Attributer {
11111115
@discardableResult
11121116
fileprivate func applyAttributes(_ attributeName: String, value: AnyObject) -> Attributer {
11131117
for range in self.ranges {
1118+
guard range.location != NSNotFound else { return self }
11141119
self.attributedText.addAttribute(NSAttributedString.Key(rawValue: attributeName), value: value, range: range)
11151120
}
11161121
return self

0 commit comments

Comments
 (0)