I wrote a simple extension for decoding html objects:
extension String { func htmlDecode() -> String { if let encodedData = self.data(using: String.Encoding.unicode) { let attributedString = try! NSAttributedString(data: encodedData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.unicode], documentAttributes: nil) return attributedString.string } return self } }
Now it throws an error on the line if let attributedString β¦ :
*** Application termination due to an uncaught exception "NSRangeException", reason: "*** - [__ NSArrayM objectAtIndex:]: index 4 outside the bounds [0 .. 2] '
And self not zero or something, just String , like this:
self = (String) "...ΓΌber 25'000 Franken..."
Where is this weird NSArray -exception coming from?
ios swift nsattributedstring
Fabio poloni
source share