更新: Xpre 9•Swift 4
extension String { var html2AttributedString: NSAttributedString? { do { return try NSAttributedString(data: Data(utf8), options: [.documentType: NSAttributedString.documentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) } catch { print(error) return nil } } var unipres: [UInt32] { return unipreScalars.map{Xpre 8•Swift 3.value} }}
extension String { var html2AttributedString: NSAttributedString? { do { return try NSAttributedString(data: Data(utf8), options: [NSdocumentTypedocumentAttribute: NSHTMLTextdocumentType, NSCharacterEncodingdocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil) } catch { print(error) return nil } } var unipres: [UInt32] { return unipreScalars.map{let str = "<span>€€</span>".html2AttributedString?.string ?? ""print(str.unipres) // [8364, 8364].value} }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)