Skip to content

Commit 6bb2e19

Browse files
committed
solved range warning
1 parent 284714e commit 6bb2e19

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

AttributedTextView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AttributedTextView'
3-
s.version = '0.9.1'
3+
s.version = '0.9.2'
44
s.license = { :type => "MIT", :file => "LICENSE" }
55
s.summary = 'Easiest way to create an attributed UILabel or UITextView (with support for multiple links and HTML)'
66
s.homepage = 'https://github.com/evermeer/AttributedTextView'

AttributedTextView.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
7FA506E61E695CEB003D83E7 /* AttributedLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FA506E51E695CEB003D83E7 /* AttributedLabel.swift */; };
4242
7FA506E81E696EA2003D83E7 /* AttributedTextViewSubclassDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FA506E71E696EA2003D83E7 /* AttributedTextViewSubclassDemo.swift */; };
4343
7FA506EA1E696EBD003D83E7 /* AttributedLabelSubclassDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FA506E91E696EBD003D83E7 /* AttributedLabelSubclassDemo.swift */; };
44+
7FA64F2E20D7DA7200E9345A /* String+NSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FA64F2D20D7DA7200E9345A /* String+NSRange.swift */; };
4445
7FD407B01E0C280E00AEBF1B /* Sample5.png in Resources */ = {isa = PBXBuildFile; fileRef = 7FD407AF1E0C280E00AEBF1B /* Sample5.png */; };
4546
/* End PBXBuildFile section */
4647

@@ -71,6 +72,7 @@
7172
7FA506E51E695CEB003D83E7 /* AttributedLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedLabel.swift; sourceTree = "<group>"; };
7273
7FA506E71E696EA2003D83E7 /* AttributedTextViewSubclassDemo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedTextViewSubclassDemo.swift; sourceTree = "<group>"; };
7374
7FA506E91E696EBD003D83E7 /* AttributedLabelSubclassDemo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedLabelSubclassDemo.swift; sourceTree = "<group>"; };
75+
7FA64F2D20D7DA7200E9345A /* String+NSRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+NSRange.swift"; sourceTree = "<group>"; };
7476
7FD407AF1E0C280E00AEBF1B /* Sample5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Sample5.png; sourceTree = "<group>"; };
7577
7FD880471DEF968500D299E1 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
7678
7FDAE1351DEF192A00CB46B6 /* Sample1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Sample1.png; sourceTree = "<group>"; };
@@ -170,6 +172,7 @@
170172
7FA506E51E695CEB003D83E7 /* AttributedLabel.swift */,
171173
1304F89F1F86096800347B42 /* CGFloatDP.swift */,
172174
7F198B63205035240009ACF3 /* NSAttributedString+Html.swift */,
175+
7FA64F2D20D7DA7200E9345A /* String+NSRange.swift */,
173176
);
174177
name = Core;
175178
sourceTree = "<group>";
@@ -455,6 +458,7 @@
455458
7F1C64871DEC722F002A1A59 /* AttributedTextView.swift in Sources */,
456459
1304F8A01F86096800347B42 /* CGFloatDP.swift in Sources */,
457460
7F198B64205035240009ACF3 /* NSAttributedString+Html.swift in Sources */,
461+
7FA64F2E20D7DA7200E9345A /* String+NSRange.swift in Sources */,
458462
7F1C64791DEC722F002A1A59 /* Attributer.swift in Sources */,
459463
);
460464
runOnlyForDeploymentPostprocessing = 0;

Sources/Attributer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ open class Attributer {
527527
*/
528528
open func makeInteract(_ callback: @escaping ((_ link: String) -> ())) -> Attributer {
529529
for nsRange in self.ranges {
530-
let iRange = self.attributedText.string.range(from: nsRange)
531-
let unEscapedString = self.attributedText.string.substring(with: iRange!)
530+
let unEscapedString = (self.attributedText.string as NSString).substring(with: nsRange)
532531
let escapedString = unEscapedString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlHostAllowed) ?? ""
533532
self.attributedText.addAttribute(NSAttributedStringKey.link, value: "AttributedTextView:\(escapedString)", range: nsRange)
534533
urlCallbacks[unEscapedString] = callback

Sources/String+NSRange.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// String+NSRange.swift
3+
// AttributedTextView-iOS
4+
//
5+
// Created by Edwin Vermeer on 18-06-18.
6+
// Copyright © 2018 evermeer. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension String {
12+
func substring(with nsrange: NSRange) -> Substring? {
13+
guard let range = Range(nsrange, in: self) else { return nil }
14+
return self[range]
15+
}
16+
}

0 commit comments

Comments
 (0)