Fix crash on invalid URL
This commit is contained in:
parent
8b3f1ba30d
commit
2469622a51
|
@ -38,9 +38,9 @@ class StatusTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
let doc = try! SwiftSoup.parse(status.content)
|
let doc = try! SwiftSoup.parse(status.content)
|
||||||
let body = doc.body()!
|
let body = doc.body()!
|
||||||
print("---")
|
// print("---")
|
||||||
print(status.content)
|
// print(status.content)
|
||||||
print("---")
|
// print("---")
|
||||||
|
|
||||||
let text = attributedTextForNode(body)
|
let text = attributedTextForNode(body)
|
||||||
contentLabel.attributedText = text
|
contentLabel.attributedText = text
|
||||||
|
@ -74,13 +74,16 @@ class StatusTableViewCell: UITableViewCell {
|
||||||
case "br":
|
case "br":
|
||||||
attributed.append(NSAttributedString(string: "\n"))
|
attributed.append(NSAttributedString(string: "\n"))
|
||||||
case "a":
|
case "a":
|
||||||
|
if let link = try? node.attr("href"),
|
||||||
|
let url = URL(string: link) {
|
||||||
let linkRange = NSRange(location: 0, length: attributed.length)
|
let linkRange = NSRange(location: 0, length: attributed.length)
|
||||||
let linkAttributes: [NSAttributedString.Key: Any] = [
|
let linkAttributes: [NSAttributedString.Key: Any] = [
|
||||||
.foregroundColor: UIColor.blue
|
.foregroundColor: UIColor.blue
|
||||||
]
|
]
|
||||||
attributed.setAttributes(linkAttributes, range: linkRange)
|
attributed.setAttributes(linkAttributes, range: linkRange)
|
||||||
let link = try! node.attr("href")
|
|
||||||
links[linkRange] = URL(string: link)!
|
links[linkRange] = url
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue