gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:45:28 27 4
gpt4 key购买 nike

您好,我的应用程序在部署目标设置中以 iOS8.2 为目标。我试图将应用程序从 swift3 转换为 swift 4。它可以工作,但不能在 iPhone 5s iOS 8.4 的模拟器中工作。问题是这样的:

cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

所以我尝试了这个:

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)
}

但我无法编译此代码 Xcode 显示 iOS 8.4 分支的异常:

Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey'

我对将 base sdk 设置为 8.x 有意见,但我没有找到这样做的理由。在build设置中,我只能将基本 sdk 设置为 11.x 版本。

我会感谢每一个想法。

最佳答案

仅使用这一行:

cell.lblHeader.attributedText = try NSAttributedString(data: htmlData, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)

关于ios - Xcode 9.1 Swift 4,如果使用 "if#available",则无法使用 NSDocumentTypeDocumentAttribute 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47281756/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com