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

Posted

技术标签:

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

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

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

关于以下内容:

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 单身。 【参考方案1】:

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

【讨论】:

以上是关于“NSAttributedString”类型的值没有成员“addAttributes”的主要内容,如果未能解决你的问题,请参考以下文章

select下拉表单 选取并点击查询,可是页面返回后,选取的select表单的值没了,回到默认值,怎么办

无法使用类型为 [重复] 的参数列表调用类型“NSAttributedString”的初始化程序

Swift 4.2 类型“NSAttributedString.Key”没有成员“accessibilitySpeechPitch”

NSAttributedString 类型在 tableView 中没有下标成员

iOS-NSAttributedString

使用 NSAttributedString 更改字符串颜色?