小编Jan*_*lek的帖子

Xcode 9.1 Swift 4,如果使用"if #available",则无法使用NSDocumentTypeDocumentAttribute进行编译

嗨我有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版本.

我会感激每一个想法.

xcode ios swift

8
推荐指数
2
解决办法
6000
查看次数

标签 统计

ios ×1

swift ×1

xcode ×1