calling
NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocume
Maybe its too late to answer this question, but may help others.
Actually NSAttributedString and NSHTMLTextDocumentType must run asynchronously either on main queue or a global queue.
You can use it in a background thread but you have to dispatch your code block containing NSAttributedString's initializer on a global or main queue. For example:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in
print("Started on \(NSThread.currentThread())")
let encodedData = "Hello".dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]
let attributedString = (try? NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) ?? NSAttributedString(string: ""))
print("Finished")
}