【发布时间】:2019-09-16 01:50:23
【问题描述】:
将我的代码从 swift 3 转换为 4 并得到错误
无法将类型“[String : Any]”的值转换为预期的参数类型“[NSAttributedStringKey : Any]”
上线
attributedString.addAttributes(boldAttributes, range: NSRange(location: index, length: linkType.keyPhrase.count))
加粗属性突出显示
这是完整的代码
private func addLink(_ linkType: AttributedURLType, attributedString: NSMutableAttributedString) {
let indeces = attributedString.string.indices(of: linkType.keyPhrase)
let boldAttributes: [String : Any] = [
NSAttributedStringKey.font.rawValue: LocalConstants.termsBoldFont,
NSAttributedStringKey.link.rawValue: linkType.url
]
for index in indeces {
attributedString.addAttributes(boldAttributes, range: NSRange(location: index, length: linkType.keyPhrase.count))
}
}
【问题讨论】:
-
移除 rawValue
标签: ios swift xcode facebook objectmapper