如何使用字符串扩展
How to make use of a string extension
我将迁移到 Swift 2 并尝试解决所有编译错误并找到下面的 link 代码,这显然是处理 html 文本的新方法,但我看不到如何在 swift 2?
中的函数中使用它
在swift 1.2中我使用了:
attributedText.appendAttributedString(htmlString.html2AttributedString)
和
extension String {
var html2AttributedString:NSAttributedString {
return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!,
options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding],
documentAttributes: nil,
error: nil)!
}
}
这显然是一种新方法
您可以使用 link 中提到的扩展,如下所示
var str = String(htmlEncodedString: "abc");
我将迁移到 Swift 2 并尝试解决所有编译错误并找到下面的 link 代码,这显然是处理 html 文本的新方法,但我看不到如何在 swift 2?
中的函数中使用它在swift 1.2中我使用了:
attributedText.appendAttributedString(htmlString.html2AttributedString)
和
extension String {
var html2AttributedString:NSAttributedString {
return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!,
options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding],
documentAttributes: nil,
error: nil)!
}
}
这显然是一种新方法
您可以使用 link
var str = String(htmlEncodedString: "abc");