【问题标题】:Value of type 'NSAttributedString' has no member 'addAttributes'“NSAttributedString”类型的值没有成员“addAttributes”
【发布时间】:2018-03-31 19:17:31
【问题描述】:

我查了documentation,方法就在那里。

当我查看 .h 文件时,我确实看到了该函数。我已经尝试清理和重建,但在迁移到 Swift 4 后仍然出现此错误。

“NSAttributedString”类型的值没有成员“addAttributes”

关于以下内容:

var options:[NSAttributedString.DocumentReadingOptionKey : Any] = [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html]
var attributedString = try NSAttributedString(data: data, options: options, documentAttributes: nil)
let range = (attributedString.string as NSString).range(of: attributedString.string)
attributedString.addAttributes(baseAttributes, range: range) // ERROR!

【问题讨论】:

  • 这是NSMutableAttributedString的方法。
  • 啊,好吧,这一定是在翻译中丢失了。谢谢。
  • 如果您愿意,可以使用addAttribute 单身。

标签: swift nsattributedstring swift4


【解决方案1】:

对于谷歌带来的其他人,我错过了import UIKit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2018-01-15
    相关资源
    最近更新 更多