Skip to content

Instantly share code, notes, and snippets.

@maltalef
maltalef / HTML_to_NSAttributedString.swift
Created May 16, 2019 16:23
converting HTML to NSAttributedString "pseudo-asynchronously"
import UIKit
extension NSAttributedString {
static func fromHTML(_ html: String, execute: @escaping (NSAttributedString?) -> Void) {
DispatchQueue.main.async {
let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]
// only run on main queue
let result = try? NSAttributedString(data: Data(html.utf8), options: options, documentAttributes: nil)