Hi,
This is my code:
do{
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,
NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue]
let string = try NSMutableAttributedString(data: data, options: options, documentAttributes: nil)
let attributes: [NSAttributedString.Key: Any] = [.font : labelFont, .foregroundColor : textColor]
string.addAttributes(attributes, range: NSRange(location: 0, length: string.length))
return string
}catch{
return NSAttributedString()
}
This is the crash report I got. I believe the problem originates with the creation of the NSMutableAttributedString on line 8 above.
Last Exception Backtrace:
0 CoreFoundation 0x1d2608ec4 __exceptionPreprocess + 228 (NSException.m:172)
1 libobjc.A.dylib 0x1d17d9a40 objc_exception_throw + 56 (objc-exception.mm:557)
2 CoreFoundation 0x1d251eb3c +[NSException raise:format:arguments:] + 104 (NSException.m:136)
3 Foundation 0x1d305b980 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 88 (NSException.m:165)
4 UIKitCore 0x1ff7d081c _prepareForCAFlush + 632 (UIApplication.m:2663)
5 UIKitCore 0x1ff7ff8d0 _beforeCACommitHandler + 20 (UIApplication.m:2764)
6 CoreFoundation 0x1d25987cc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 (CFRunLoop.c:1822)
7 CoreFoundation 0x1d2593460 __CFRunLoopDoObservers + 412 (CFRunLoop.c:1932)
8 CoreFoundation 0x1d2593210 CFRunLoopRunSpecific + 468 (CFRunLoop.c:3249)
9 UIFoundation 0x1dcc1f368 -[NSHTMLReader _loadUsingWebKit] + 1728 (NSHTMLReader.m:2562)
10 UIFoundation 0x1dcc2233c -[NSHTMLReader attributedString] + 28 (NSHTMLReader.m:3139)
11 UIFoundation 0x1dcc6f3ec _NSReadAttributedStringFromURLOrData + 8120 (NSAttributedStringAdditions.m:2405)
12 UIFoundation 0x1dcc22278 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWitData:options:documentAttrib... + 136 (NSAttributedStringAdditions.m:1385)
13 LifeCoach 0x104370ca8 specialized @nonobjc NSMutableAttributedString.init(data:options: (<compiler-generated>:0)
14 LifeCoach 0x104370ff0 specialized String.convertHtml(labelFont:textColor:stripLinks:) + 704 (<compiler-generated>:0)
I am not sure what could have caused this problem, or why the execption wasn't simply caught by my exception handler.
Frank