嗨我有app的目标是在部署目标设置中定位iOS8.2.我试图将应用程序从swift3转换为swift 4.它可以工作,但不适用于iPhone 5s iOS 8.4的模拟器.问题是这样的:
cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
Run Code Online (Sandbox Code Playgroud)
所以我试过这个:
if #available(iOS 11, *){
cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
}
if #available(iOS 8.4, *){
cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
}
Run Code Online (Sandbox Code Playgroud)
但我无法编译此代码Xcode显示iOS 8.4分支的异常:
Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey'
Run Code Online (Sandbox Code Playgroud)
我有关于将基本sdk设置为8.x的意见,但我没有找到这样做.在构建设置中,我能够将base sdk设置为11.x版本.
我会感激每一个想法.
Roy*_*yBS 25
仅使用此行:
cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
Run Code Online (Sandbox Code Playgroud)
Ser*_*ens 11
看起来像是Swift 4.1.2的正确语法:
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,
NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6000 次 |
| 最近记录: |