swift – 在扩展文件中使用未解析的标识符错误?
发布时间:2020-12-14 05:21:32 所属栏目:百科 来源:网络整理
导读:我正在进行扩展,将html转换为属性字符串,代码为 extension String {var htmlToAttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return nil } do { return try NSAttributedString(data: data,options: [NSDocumentType
我正在进行扩展,将html转换为属性字符串,代码为
extension String { var htmlToAttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return nil } do { return try NSAttributedString(data: data,options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue],documentAttributes: nil) } catch let error as NSError { print(error.localizedDescription) return nil } } var html2String: String { return htmlToAttributedString?.string ?? "" } 我收到以下3个相同的错误
我假设我犯了一个错误的语法导致3相同的错误但我无法看到扩展需要什么? 谢谢
NSDocumentTypeDocumentAttribute,NSCharacterEncodingDocumentAttribute,NSHTMLTextDocumentType和
文档属性词典的其他键和值 定义于 AppKit框架(macOS)或UIKit框架(iOS): #if os(macOS) import AppKit #elseif os(iOS) import UIKit #endif (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |