I am Getting [_WebSafeForwarder forwardInvocation:] and crash report as following on crashlytics. Unable to reproduce the same condition in my code. I added webview.delega
If you are not insisting on using the NSAttributedString class and you are Ok with just using the String class, check out this project here:
https://github.com/adela-chang/StringExtensionHTML/blob/master/Pod/Classes/StringExtensionHTML.swift
It is a bit old and not supported but if you just copy the two Swift files HTMLEntityMapping.swift and StringExtensionHTML.swift, you are good to go.
The top two properties in the extension are the ones to use.
extension String {
/// Returns a new string made by removing in the `String`
/// anything enclosed in HTML brackets <>
public var stringByStrippingHTMLTags: String {
return replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression, range: nil);
}
/// Returns a new string made by replacing in the `String`
/// all HTML character entity references with the corresponding
/// character.
public var stringByDecodingHTMLEntities: String {
return decodeHTMLEntities().decodedString
}
What they do is strip any unwanted html tags found in the list in HTMLEntityMapping.swift.