我有一个HTML字符串,我想用它来制作一个NSAttributedString
。这在Objective-C中相当简单:
NSData* html;
[[NSAttributedString alloc] initWithHTML:html documentAttributes:nil];
这在Swift中应该相当简单,但我显然无法做到正确。我有这个:
import Foundation
import AppKit
let html: Data = ...
let str = NSAttributedString(HTML: html, documentAttributes: nil)
但是,这会导致错误:
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
这是来自REPL,但Xcode给出了同样的错误。当然,“找到这个候选人”是指<unknown>:0
,所以我不知道歧义来自何处。
如何在Swift 3.0中从HTML数据创建NSAttributedString
?