Skip to content Skip to sidebar Skip to footer

Nsattributedstring From Html On Main Thread Behaves As If Multithreading

I'm converting some HTML to an NSAttributedString on the main thread (the way Apple tells you to). It takes some time and then it continues executing the rest of the block. Now, if

Solution 1:

My original suspicion was correct. The implementation of NSAttributedString init(data:options:documentAttributes:) makes calls to CFRunLoopRun(). Doing so allows other queued up blocks/closures on the queue (main queue in this case) to run.

This is why you are seeing what appears to be asynchronous output on the main queue.

I put your code into a simple command line app and set a breakpoint on the print in dispatchStuff. The stack trace shows that during the call to the NSAttributedString init there is an internal call to _CGRunLoopRun which results in a call to one of the queued closures from dispatchStuff.

enter image description here

Post a Comment for "Nsattributedstring From Html On Main Thread Behaves As If Multithreading"