Tag: nsattributedstringkey

无法将typesNSAttributedString.DocumentAttributeKey的值转换为.DocumentReadingOptionKey

我在互联网上的某个地方发现了这个string扩展,它允许我把html代码转换成属性string: func html2AttributedString() -> NSAttributedString { return try! NSAttributedString(data: self.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) } 它在Swift 3中运行良好,但是在Swift 4中,Xcode抱怨: 无法将types“NSAttributedString.DocumentAttributeKey”的值转换为期望的字典键types“NSAttributedString.DocumentReadingOptionKey” 我该如何解决?