• 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
Creating NSAttributedString objects using WebKit in secondary thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating NSAttributedString objects using WebKit in secondary thread


  • Subject: Creating NSAttributedString objects using WebKit in secondary thread
  • From: Dragan Milić <email@hidden>
  • Date: Mon, 11 May 2009 19:53:22 +0200

Hello all,

Is there any way to initialise and use WebKit out of the main thread? I know this message may look like good candidate for the Webkit-dev mailing list, but I actually don't want to use WebKit directly, it's just a consequence of trying to create NSAttributedString instance from data in memory. Here is the longer story...

I need to create NSAttributedString objects and draw them onto the NSImage object (which holds the current graphic context). The attributed strings are created from data in memory buffer and since it is not know at the time of creation what kind of data the buffer holds, I use -[NSAttributedString initWithData:options:documentAttributes:error:] method, which examines the data and loads it using whatever format it seems to contain. Now, according to the documentation:

"In Mac OS X v10.3, the options key @"UseWebKit" specifies that WebKit- based HTML importing be used (and must be specified for the other options to be recognised). In Mac OS X v10.4 and later, WebKit is always used for HTML documents, and all of the options except @"UseWebKit" are recognised (attribute identifiers are available on Mac OS X v10.4 and later; use actual string value keys for Mac OS X v10.3)".

Since the application in question supports Tiger and above, the WebKit is always used. The problem is that string creation and drawing needs to be executed in the secondary thread and then the WebKit complains whenever the data in the buffer contains a HTML/XML document.

Sometimes an exception "Cannot use WebKit in secondary thread" is thrown, and sometimes only a warning about threading violation is printed out onto the console (with remark that it would be printed only once) and creation of HTML-based attributed strings works, but is very crash-prone. In any case, operation is far from being reliable.

Is there any way to solve this without jumping into the main thread for strings creation?

Thanks in advance,
Milke
_______________________________________________

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: Creating NSAttributedString objects using WebKit in secondary thread
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: converting a characer to a keycode
  • Next by Date: Re: Creating NSAttributedString objects using WebKit in secondary thread
  • Previous by thread: Re: [iPhone] UITableViewController headache
  • Next by thread: Re: Creating NSAttributedString objects using WebKit in secondary thread
  • Index(es):
    • Date
    • Thread