• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?


  • Subject: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • From: Jean Suisse <email@hidden>
  • Date: Wed, 15 May 2013 15:58:20 +0200

Thanks for your replies.
Unfortunately, I can't easily avoid initWithHTML:dataUsingEncoding:documentAttributes:
But I can postpone it long enough to move its execution to an other thread (serial dispatch queue).
That solves the issue.

Jean

On 8 mai 2013, at 21:14, Jens Alfke <email@hidden> wrote:

>
> On May 7, 2013, at 3:52 PM, Ken Thomases <email@hidden> wrote:
>
>> Yes, it can.  Under the hood, NSAttributedString is using WebKit for HTML rendering.  In part that means that, when invoked from a background thread, it has to shunt the work to the main thread.  But it also means the main thread may have to run the run loop during the call.  It's a nuisance, but it's necessary since HTML can have references to external resources that need to be loaded.
>
> I’ve had trouble with this method in the past, for exactly that reason — you can get weird reentrancy problems from runloop sources like timers being invoked while in the middle of the call. (It’s also pretty slow.)
>
> IMHO it’s best to avoid this method if you can. For example, the last time this came up all I needed was the plain text, so I wrote a little string transformer to strip out HTML tags and expand HTML entities. For more involved work you could use NSXMLParser (with the “tidy” option) to parse the HTML into a DOM and then walk through that.
>
> —Jens


-----------
Jean Suisse
Institut de Chimie Moléculaire de l’Université de Bourgogne
(ICMUB) — UMR 6302


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
      • From: Ken Thomases <email@hidden>
References: 
 >Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop? (From: Jean Suisse <email@hidden>)
 >Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop? (From: Ken Thomases <email@hidden>)
 >Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Displaying "Trebuchet MS" font
  • Next by Date: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Previous by thread: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Next by thread: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Index(es):
    • Date
    • Thread