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?

8
  • Can you show us an example of "html with few characters" you are trying?
    – ahwulf
    Feb 4, 2015 at 15:10
  • Sure @"Ferty event list try <b>bold</b>" ,even if I don't add any tag is really slow
    – Andrea
    Feb 4, 2015 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 4, 2015 at 15:29
  • You might this stackoverflow.com/questions/4217820/…
    – ahwulf
    Feb 4, 2015 at 15:31
  • 2
    Oh Apple you make such irritating bugs :-)
    – ahwulf
    Feb 4, 2015 at 21:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.