NSAttributedString initWithData:options:documentAttributes:error: painfully slow

孤街浪徒 提交于 2019-12-23 20:46:28

问题


I'm using those line of codes to create an attributed string from a simple HTML string:

  NSDictionary *importParams = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding) };
    NSError *error = nil;
    NSData *stringData = [HTML dataUsingEncoding:NSUTF8StringEncoding] ;
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:stringData options:importParams documentAttributes:NULL error:&error];

The issue is that is really slow (about seconds on simulator)even for few characters.
I don not understand the reason behind that and I don't want to use third party libs with custom HTML parser.
Is there any other way to create attributed string from HTML text faster than this?

来源:https://stackoverflow.com/questions/28316899/nsattributedstring-initwithdataoptionsdocumentattributeserror-painfully-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!