NSAttributedString initWithData:options:documentAttributes:error: painfully slow
Asked Answered
C

0

3

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?

Carmelacarmelia answered 4/2, 2015 at 8:38 Comment(8)
Can you show us an example of "html with few characters" you are trying?Thiazine
Sure @"Ferty event list try <b>bold</b>" ,even if I don't add any tag is really slowCarmelacarmelia
Hmm it is slow. I ran 4 in a row and the times were 0.5, 0.35,0.35,0.35 seconds for that tiny string running in Xcode 6.X iPad simulator.Thiazine
You might this #4218320Thiazine
@Thiazine thank you for taking time by testing yourself. I will try on device to see if it a specific simulator issue. I've also read the specific link, in the comments they state the same, on iOS7 it seems to be faster but not so much.Carmelacarmelia
Oh Apple you make such irritating bugs :-)Thiazine
@Andrea, have you ever find a way to solve this issue? If yes, please add your thoughts.Holle
@hagile no, I just used a plain text :(Carmelacarmelia

© 2022 - 2024 — McMap. All rights reserved.