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?

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • Can you show us an example of "html with few characters" you are trying? – ahwulf Feb 04 '15 at 15:10
  • Sure @"Ferty event list try bold" ,even if I don't add any tag is really slow – Andrea Feb 04 '15 at 15:16
  • 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. – ahwulf Feb 04 '15 at 15:29
  • You might this http://stackoverflow.com/questions/4217820/convert-html-to-nsattributedstring-in-ios – ahwulf Feb 04 '15 at 15:31
  • @ahwulf 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. – Andrea Feb 04 '15 at 20:15
  • 2
    Oh Apple you make such irritating bugs :-) – ahwulf Feb 04 '15 at 21:09
  • @Andrea, have you ever find a way to solve this issue? If yes, please add your thoughts. – Hemang Nov 18 '15 at 09:47
  • @hagile no, I just used a plain text :( – Andrea Nov 18 '15 at 09:54

0 Answers0