class Markdown: NSObject {
func markdownString(stringForVideoDescription:NSString) -> NSMutableAttributedString {
var options = [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType]
var error:NSError?
var markdown:NSString = stringForVideoDescription
var html:NSString = MMMarkdown.HTMLStringWithMarkdown(markdown, error: &error)
var markdownAttributedString:NSMutableAttributedString = NSMutableAttributedString(data: html.dataUsingEncoding(NSUTF32StringEncoding)!, options: options, documentAttributes: nil, error: &error)!
if let font: UIFont = UIFont(name: "Marion-Regular", size: 14) {
markdownAttributedString.addAttributes([NSUnderlineStyleAttributeName:NSUnderlineStyleAttributeName], range: NSMakeRange(0, markdownAttributedString.length))
}
print(html) // used to see that markdown is in fact working
return markdownAttributedString
}
}
此代码在之前工作,直到Swift更改,现在显示错误在线:
var markdownAttributedString:NSMutableAttributedString = NSMutableAttributedString(data: html.dataUsingEncoding(NSUTF32StringEncoding)!, options: options, documentAttributes: nil, error: &error)!
错误是“没有更多上下文的表达式类型不明确”
我看到其他人有问题和解决方案,但这些对我不起作用。我试过了:
var markdownAttributedString: [NSMutableAttributedString: NSObject]...
我尝试用NSError交换出该行中的错误,因此不再是可选的。我试过删除!在各个地方,因为这是其他职位的建议。有什么建议?谢谢!