I have UITableView with dynamic sizing cells that displays list of comments in HTML format and I faced with the problem that NSAttributedString renders HTML content extremel
ABout the slow parsing of the HTML into a string: The first time you create an attributed string of HTML, iOS creates all sorts of extra threads needed to parse the string, among which JavascriptCore engine.
Before parsing the first NSAttributedString from HTML:
And immediately after:
So you can imagine it takes almost a second sometimes to start this all up.
Subsequent calls are much faster. My workaround was to parse HTML in the application:didFinishingLaunchingWithOptions:
function in the Appdelegate, so that I had all necessary frameworks in memory when needed (Objective-C):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSMutableAttributedString *attrStringFromHtml = [[NSMutableAttributedString alloc]
initWithData: [@"<span>html enabled</span>" dataUsingEncoding:NSUnicodeStringEncoding
allowLossyConversion:NO]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
documentAttributes:nil error:nil];
NSLog(@"%@",[attrStringFromHtml string]);
return YES;
}
Also see this answer.