NSAttributedString initWithData:options:documentAttributes:error: 非常慢

2024-04-09

我使用这些代码行从简单的 HTML 字符串创建属性字符串:

  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];

问题是,即使对于几个角色来说,速度也非常慢(在模拟器上大约几秒钟)。
我不明白其背后的原因,并且我不想将第三方库与自定义 HTML 解析器一起使用。
还有其他方法可以比这更快地从 HTML 文本创建属性字符串吗?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NSAttributedString initWithData:options:documentAttributes:error: 非常慢 的相关文章