I have an HTML string and I want to make an NSAttributedString
out of it. This is fairly simple in Objective-C:
NSData* html;
[[NSAttributedString alloc] initWithHTML:html documentAttributes:nil];
This should be fairly simple in Swift as well, but I apparently can't get it right. I have this:
import Foundation
import AppKit
let html: Data = ...
let str = NSAttributedString(HTML: html, documentAttributes: nil)
However, this causes an error:
error: repl.swift:5:11: error: ambiguous use of 'init(HTML:documentAttributes:)'
let str = NSAttributedString(HTML: html, documentAttributes: nil)
^
found this candidate
found this candidate
This is from the REPL, but Xcode gives the same error. Of course, "found this candidate" refers to <unknown>:0
, so I have no idea where the ambiguity is coming from.
How do I create a NSAttributedString
from HTML data in Swift 3.0?